{"id":20053,"date":"2020-07-24T02:06:13","date_gmt":"2020-07-24T09:06:13","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=20053"},"modified":"2023-12-01T03:56:01","modified_gmt":"2023-12-01T11:56:01","slug":"python-recursion","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-recursion\/","title":{"rendered":"Python Recursion: A Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Use Python Recursion<\/h2>\n\n\n\n<p>Python recursion is an intimidating topic for beginners. Let\u2019s dispel the myth that recursion is difficult by defining it. Recursion is a method of programming where a function calls itself.<br><\/p>\n\n\n\n<p>That sounds simple, right? When you get the hang of it, recursion is not a difficult concept.<br><\/p>\n\n\n\n<p>In this Python tutorial, we\u2019re going to talk about recursion and how it works. We\u2019ll walk through an example of recursion using factorial functions to help you get started with this method of programming.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Recursion?<\/h2>\n\n\n\n<p>Recursion is where you define something in terms of itself.<br><\/p>\n\n\n\n<p>A recursive function solves problems by calling itself over again. This behavior is supported in most major programming languages, such as Python. They are a crucial part of computer science and data science.<br><\/p>\n\n\n\n<p>Recursion is useful when the solution to a problem can be found by breaking it down into smaller problems which all use the same formula. These types of problems are often called \u201crecursive algorithms.\u201d The key to solving them is in the name!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Iterative vs. Recursive<\/h2>\n\n\n\n<p>There are two ways to solve an algorithm: iteratively or recursively.<br><\/p>\n\n\n\n<p>Iterative solutions to algorithms are regarded as \u201cpowerful but ugly.\u201d They get the job done, but they don\u2019t exactly do it in the most elegant way. To properly understand recursive algorithms, we need to look at iterative functions.<br><\/p>\n\n\n\n<p>An iterative <a href=\"https:\/\/careerkarma.com\/blog\/python-functions\/\">function<\/a> is a function that solves a problem using a loop. It will execute the code inside a loop until that loop is complete. A recursive function is a function that breaks a problem down into smaller parts and solves each part by calling itself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Factorials: The Iterative Example<\/h2>\n\n\n\n<p>Factorials are a good way to demonstrate recursion and iterative thinking. In math, factorials are the sum of a number and every number before it multiplied together.<br><\/p>\n\n\n\n<p>The factorial of 5 is equal to 5 * 4 * 3 * 2 * 1. The factorial of 2 is equal to 2 * 1.<br><\/p>\n\n\n\n<p>To calculate a factorial, we can write an iterative function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def factorial(number):\n\ttotal = 1\n\tfor n in range(1, number + 1):\n\t\ttotal = total * n\n\treturn total<\/pre><\/div>\n\n\n\n<p>This function uses a <a href=\"https:\/\/careerkarma.com\/blog\/python-for-loop\/\">for loop<\/a> to iterate through all numbers <a href=\"https:\/\/careerkarma.com\/blog\/python-range\/\">in the range<\/a> of 1 and the number we have specified plus 1. For each iteration, the number the loop is iterating over is multiplied by the total. Let\u2019s call our function to find the factorial:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>answer = factorial(4)\nprint(answer)<\/pre><\/div>\n\n\n\n<p>Our code returns: 24. To arrive at this solution, our code runs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1 * 1 = 1<\/li><li>2 * 2 = 4<\/li><li>4 * 3 = 8<\/li><li>8 * 4 = 24<\/li><\/ul>\n\n\n\n<p>As you can see, our code multiplies 4 with all the numbers lower than it and then itself.<br><\/p>\n\n\n\n<p>This code is functional. The only drawback is that it\u2019s not as elegant as it could be. That\u2019s where recursive functions come in handy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Factorials: The Recursion Example<\/h2>\n\n\n\n<p>Let\u2019s write a recursive function that calculates a factorial. Open up a new Python file and paste in the following code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def factorial(number):\n\tif number == 1:\n\t\treturn 1\n\telse:\n\t\treturn (number * factorial(number - 1))<\/pre><\/div>\n\n\n\n<p>This code uses the recursive approach. When this function is run, an <a href=\"https:\/\/careerkarma.com\/blog\/python-if-else\/\">\u201dif\u201d statement<\/a> is executed. This statement checks whether the number passed to the function is equal to 1. If it is, our function returns 1. Otherwise, the factorial of our number is calculated.<br><\/p>\n\n\n\n<p>This calculation works by multiplying the number passed to the function by the factorial of the previous number. This function is called again and again until \u201cnumber\u201d is equal to 1. Each time the function is called, the value of \u201cnumber\u201d is reduced by 1.<br><\/p>\n\n\n\n<p>Let\u2019s give our code a try with the number 4:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>answer = factorial(4)\nprint(answer)<\/pre><\/div>\n\n\n\n<p>The answer 24 is returned. Our answer is correct; it\u2019s the same as our last example. We have found the solution to this problem recursively instead of iteratively.<br><\/p>\n\n\n\n<p>Do you still need a little bit of help? Let\u2019s walk through another example of recursion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Recursion with the Fibonacci Sequence<\/h2>\n\n\n\n<p>The fibonacci sequence is a mathematical sequence where each number is the sum of the two previous numbers. This sequence starts with: 0, 1, 1, 2, 3, 5, 8, 13, and so on.<br><\/p>\n\n\n\n<p>This sequence adds two numbers to find the next number. This makes it ideal for recursion.<br><\/p>\n\n\n\n<p>Open up a Python file and paste in this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def fibonacci(number):\n\tif number &lt;= 1:\n\t\treturn number\n\telse:\n\t\treturn(fibonacci(number - 1) + fibonacci(number - 2))<\/pre><\/div>\n\n\n\n<p>This code will calculate the sum of two preceding numbers in a list, as long as \u201cnumber\u201d is more than 1. Otherwise, \u201cnumber is returned\u201d. Now, let\u2019s call our function:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>executions = 5\n\nprint(&quot;Fibonacci Sequence:&quot;)\nfor number in range(executions):\n\tprint(fibonacci(number))<\/pre><\/div>\n\n\n\n<p>The executions variable tracks how many numbers in the fibonacci sequence we want to calculate. We use this to create a for loop which calls our <code>fibonacci()<\/code> function for each number in the range of 1 and the value of \u201cexecutions.\u201d<br><\/p>\n\n\n\n<p>Before our for loop starts, we print \u201cFibonacci Sequence:\u201d to the console. In this example, our \u201cfor\u201d loop executes:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>fibonacci(1)\nfibonacci(2)\nfibonacci(3)\nfibonacci(4)\nfibonacci(5)<\/pre><\/div>\n\n\n\n<p>Let\u2019s run our code all together and see what happens:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Fibonacci Sequence:\n0\n1\n1\n2\n3<\/pre><\/div>\n\n\n\n<p>Our code calculates the first five numbers in the fibonacci sequence. We could calculate more numbers by increasing the value of \u201cexecutions\u201d.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Recursion Depth and Base Conditions<\/h2>\n\n\n\n<p>A recursive function must have a base condition. This is a condition that stops the recursion when a particular base case is met. Without a base function, an infinite loop will be created.<br><\/p>\n\n\n\n<p>A recursive function can execute itself no more than 1,000 times by default. Once this limit is reached, an error like this appears:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>RecursionError: maximum recursion depth exceeded<\/pre><\/div>\n\n\n\n<p>Here is the base condition for our fibonacci program:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>...\nif number &lt;= 1:\n\t\treturn number\n\u2026<\/pre><\/div>\n\n\n\n<p>This condition checks if the value of \u201cnumber\u201d inside our fibonacci program is equal to or less than 1. If it is, the value of \u201cnumber\u201d is returned; otherwise, the recursive function starts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Should I Use Recursion?<\/h2>\n\n\n\n<p>What\u2019s the advantage of using recursion over iterative functions? Technically, both methods can accomplish the same result. The benefit of recursion is that it is easier to read.<br><\/p>\n\n\n\n<p>When you see a recursive function, it\u2019s clear that the answer to a problem lies in breaking it down into smaller parts. While iterative loops can sometimes be quicker, recursive functions are usually preferred due to their readability.<br><\/p>\n\n\n\n<p>Because recursive functions are easier to read, they are also easier to maintain and debug. This is especially useful when you are writing complex algorithms that may be difficult to understand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>A recursive function is a function that calls itself to find the solution to a problem.&nbsp;<br><\/p>\n\n\n\n<p>Recursive functions break down a problem into multiple parts and solves one part of the problem per iteration. Recursive functions are commonly used to calculate factorials and numbers in the fibonacci sequence. They\u2019re also used in a number of algorithms.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to start working with recursive functions in Python.<\/p>\n","protected":false},"excerpt":{"rendered":"How to Use Python Recursion Python recursion is an intimidating topic for beginners. Let\u2019s dispel the myth that recursion is difficult by defining it. Recursion is a method of programming where a function calls itself. That sounds simple, right? When you get the hang of it, recursion is not a difficult concept. In this Python&hellip;","protected":false},"author":240,"featured_media":20054,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-20053","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Recursion: A Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"A recursive function is a function that calls itself to solve a problem. On Career Karma, learn about Python recursion and how it works.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-recursion\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Recursion: A Guide\" \/>\n<meta property=\"og:description\" content=\"A recursive function is a function that calls itself to solve a problem. On Career Karma, learn about Python recursion and how it works.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-recursion\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-24T09:06:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:56:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python Recursion: A Guide\",\"datePublished\":\"2020-07-24T09:06:13+00:00\",\"dateModified\":\"2023-12-01T11:56:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/\"},\"wordCount\":1055,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-recursion\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/\",\"name\":\"Python Recursion: A Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg\",\"datePublished\":\"2020-07-24T09:06:13+00:00\",\"dateModified\":\"2023-12-01T11:56:01+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"A recursive function is a function that calls itself to solve a problem. On Career Karma, learn about Python recursion and how it works.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-recursion\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-recursion\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Recursion: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Recursion: A Guide | Career Karma","description":"A recursive function is a function that calls itself to solve a problem. On Career Karma, learn about Python recursion and how it works.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-recursion\/","og_locale":"en_US","og_type":"article","og_title":"Python Recursion: A Guide","og_description":"A recursive function is a function that calls itself to solve a problem. On Career Karma, learn about Python recursion and how it works.","og_url":"https:\/\/careerkarma.com\/blog\/python-recursion\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-24T09:06:13+00:00","article_modified_time":"2023-12-01T11:56:01+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python Recursion: A Guide","datePublished":"2020-07-24T09:06:13+00:00","dateModified":"2023-12-01T11:56:01+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/"},"wordCount":1055,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-recursion\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/","url":"https:\/\/careerkarma.com\/blog\/python-recursion\/","name":"Python Recursion: A Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg","datePublished":"2020-07-24T09:06:13+00:00","dateModified":"2023-12-01T11:56:01+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"A recursive function is a function that calls itself to solve a problem. On Career Karma, learn about Python recursion and how it works.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-recursion\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/mario-mesaglio-kesOP4tet6Y-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-recursion\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Recursion: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=20053"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/20054"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=20053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=20053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=20053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}