{"id":25543579,"date":"2022-09-30T16:04:16","date_gmt":"2022-09-30T10:34:16","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25543579"},"modified":"2023-04-27T14:53:53","modified_gmt":"2023-04-27T09:23:53","slug":"python-program-for-fibonacci-series","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/","title":{"rendered":"Python Program for Fibonacci Series"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69da75079108d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69da75079108d\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#What_is_the_Fibonacci_Sequence\" >What is the Fibonacci Sequence?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#How_to_Print_the_Fibonacci_Sequence_in_Python\" >How to Print the Fibonacci Sequence in Python<\/a><\/li><\/ul><\/nav><\/div>\n<p>&nbsp;<\/p>\n<p>In this article, we will learn how to print the Fibonacci sequence in python using two different techniques, iteration and recursion.<\/p>\n<p>Before we begin, let&#8217;s first understand some basic terminology.<\/p>\n<p><a href=\"https:\/\/entri.app\/course\/python-programming-course\/\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<h2 id=\"what-is-the-fibonacci-sequence\"><span class=\"ez-toc-section\" id=\"What_is_the_Fibonacci_Sequence\"><\/span><strong>What is the Fibonacci Sequence?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0Fibonacci Sequence\u00a0is a sequence of numbers in which a given number is the result of adding the 2 numbers that come before it. And adding the previous 2 numbers some number of times forms a series that we call the Fibonacci Series.<\/p>\n<p>The Fibonacci sequence starts with two numbers, that is 0 and 1. Then every following number is made up of adding the previous two numbers together.<\/p>\n<p>For example, take 0 and 1. They&#8217;re the first two numbers in the sequence. If you add them together, you get 1. So the sequence starts 0, 1, 1,&#8230;<\/p>\n<p>Then, to find the next number, you add the last number you have and the number before it. So 1+1 = 2. So the sequence so far is 0, 1, 1, 2, &#8230; Make sense?<\/p>\n<p>We can represent this more mathematically like 0, 1, (1) &#8211; [0 + 1]. Similarly, the next Fibonacci number is &#8211; 0, 1, 1, (2) &#8211; [1 + 1]. And so on. Here&#8217;s a diagram showing the first 10 Fibonacci numbers:<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/Fibonacci-series.png\" srcset=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/size\/w600\/2022\/04\/Fibonacci-series.png 600w, https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/Fibonacci-series.png 603w\" alt=\"Fibonacci-series\" width=\"603\" height=\"137\" \/><\/figure>\n<p>This is an example of a Fibonacci series \u2013<strong>\u00a00, 1, 1, 2, 3, 5, 8, 13, 21,<\/strong>\u00a0<strong>34<\/strong>. Within this continuous sequence, every individual number is a Fibonacci number.<\/p>\n<p>Mathematically, the Fibonacci Sequence is represented by this formula:<\/p>\n<p><strong>F(n) = F(n-1) + F(n-2)<\/strong>, where\u00a0<strong>n &gt; 1<\/strong>.<\/p>\n<p>We can use this sequence to find any nth Fibonacci number.<\/p>\n<h4 style=\"text-align: center;\"><span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;\\&quot;Ready to take your python skills to the next level? Sign up for a free demo today!\\&quot;&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1061443,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16316664},&quot;9&quot;:0,&quot;12&quot;:0,&quot;15&quot;:&quot;Arial&quot;,&quot;16&quot;:10,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/entri.app\/course\/python-programming-course\/\"><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/course\/python-programming-course\/\" target=\"_blank\" rel=\"noopener\">&#8220;Ready to take your python skills to the next level? Sign up for a free demo today!&#8221;<\/a><\/span><\/h4>\n<h2 id=\"how-to-print-the-fibonacci-sequence-in-python\"><span class=\"ez-toc-section\" id=\"How_to_Print_the_Fibonacci_Sequence_in_Python\"><\/span><strong>How to Print the Fibonacci Sequence in Python<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can write a computer program for printing the Fibonacci sequence in 2 different ways:<\/p>\n<ul>\n<li>Iteratively, and<\/li>\n<li>Recursively.<\/li>\n<\/ul>\n<p>Iteration means repeating the work until the specified condition is met. Recursion, on the other hand, means performing a single task and proceeding to the next for performing the remaining task.<\/p>\n<h3 id=\"here-s-an-iterative-algorithm-for-printing-the-fibonacci-sequence-\"><strong>Here&#8217;s an iterative algorithm for printing the Fibonacci sequence:<\/strong><\/h3>\n<ol>\n<li>Create 2 variables and initialize them with 0 and 1 (first = 0, second = 1)<\/li>\n<li>Create another variable to keep track of the length of the Fibonacci sequence to be printed (length)<\/li>\n<li>Loop (length is less than series length)<\/li>\n<li>Print\u00a0<strong>first + second<\/strong><\/li>\n<li>Update\u00a0<strong>first<\/strong>\u00a0and\u00a0<strong>second<\/strong>\u00a0variable (first will point to the second, and the second will point to first + second)<\/li>\n<li>Decrement the length variable and repeat from step 3<\/li>\n<li>Once the loop terminates, terminate the program<\/li>\n<\/ol>\n<h3 id=\"iterative-python-code-for-printing-fibonacci-sequence-\"><strong>Iterative Python Code for printing Fibonacci Sequence:<\/strong><\/h3>\n<pre class=\" language-python\"><code class=\" language-python\">def PrintFibonacci(length):\r\n    #Initial variable for the base case. \r\n    first = 0\r\n    second = 1\r\n\r\n    #Printing the initial Fibonacci number.\r\n    print(first, second, end=\" \")\r\n\r\n    #decreasing the length by two because the first 2 Fibonacci numbers \r\n    #already printed.\r\n    length -= 2\r\n    \r\n    #Loop until the length becomes 0.\r\n    while length &gt; 0:\r\n\r\n        #Printing the next Fibonacci number.\r\n        print(first + second, end=\" \")\r\n\r\n        #Updating the first and second variables for finding the next number. \r\n        temp = second\r\n        second = first + second\r\n        first = temp\r\n\r\n        #Decreasing the length that states the Fibonacci numbers to be \r\n        #printed more.\r\n        length -= 1\r\n\r\nif __name__ == \"__main__\":\r\n    print(\"Fibonacci Series - \")\r\n    PrintFibonacci(7)\r\n    pass<\/code><\/pre>\n<p>Output\u00a0for length 7:<\/p>\n<pre class=\" language-python\"><code class=\" language-python\">Fibonacci Series - \r\n1 1 2 3 5 8<\/code><\/pre>\n<p><strong>Explanation of the Code:<\/strong><\/p>\n<p>In the above code, first we have defined a function that will print the Fibonacci series. It accepts a parameter for the length, and the function needs to print the Fibonacci series.<\/p>\n<p>Next, we have created 2 variables that contain the initial 2 Fibonacci values, that is 0 and 1.<\/p>\n<p>Then we printed the first 2 values [0, 1] and decremented the length by 2, because 2 values have already been printed.<\/p>\n<p>We will run a loop for the remaining length time, and each time print the next Fibonacci value by adding the previous 2 terms that are stored in the first and second variables (that we created initially to keep track of the previous 2 values).<\/p>\n<p>Update the first and second values that will point to the previous 2 values [first = second, and second = previous first + second].<\/p>\n<p>The loop will run until the length becomes 0, which states that the required length of the Fibonacci sequence is printed.<\/p>\n<p>Then we call the function defined for printing Fibonacci from the main function by passing the argument of the required length to be printed. And there you have it!<\/p>\n<p>There is another approach for printing the Fibonacci sequence using the help of recursion. So, let\u2019s have a look at that approach, too.<\/p>\n<h4 style=\"text-align: center;\"><span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;\\&quot;Get hands-on with our python course - sign up for a free demo!\\&quot;&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1061443,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16316664},&quot;9&quot;:0,&quot;12&quot;:0,&quot;15&quot;:&quot;Arial&quot;,&quot;16&quot;:10,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/entri.app\/course\/python-programming-course\/\"><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/course\/python-programming-course\/\" target=\"_blank\" rel=\"noopener\">&#8220;Get hands-on with our python course &#8211; sign up for a free demo!&#8221;<\/a><\/span><\/h4>\n<h3 id=\"recursive-algorithm-for-printing-the-fibonacci-sequence-\"><strong>Recursive Algorithm for printing the Fibonacci Sequence:<\/strong><\/h3>\n<ul>\n<li>Accept the value of the previous first and second Fibonacci number as the length to be printed.<\/li>\n<li>Check if the length is 0 then terminate the function call.<\/li>\n<li>Print the Fibonacci value by adding the previous 2 values received in the parameter of the function (first and second).<\/li>\n<li>Recursively call the function for the updated value of the first and second, as well as the decreased value of length.<\/li>\n<\/ul>\n<p>For this recursive function call, we need to pass the initial value of Fibonacci, that is (0 and 1), in the first and second variables.<\/p>\n<p>To help you understand this algorithm better, let\u2019s see the Python implementation of the algorithms. Then we will look at an example so you can see how this recursive algorithm works.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<h3 id=\"recursive-python-code-for-printing-the-fibonacci-sequence-\"><strong>Recursive Python Code for Printing the Fibonacci Sequence:<\/strong><\/h3>\n<pre><code>def PrintFibonacci(first, second, length):\r\n\r\n    #Stop the printing and recursive calling if length reaches \r\n    #the end.\r\n    if(length == 0):\r\n        return\r\n\r\n    #Printng the next Fibonacci number.\r\n    print(first + second, end=\" \")\r\n\r\n    #Recursively calling the function by updating the value and \r\n    #decrementing the length.\r\n    PrintFibonacci(second, first+second, length-1)\r\n\r\nif __name__ == \"__main__\":\r\n    #Print initial 2 values.\r\n    print(0,1,end=\" \")\r\n\r\n    #Calling the Function to print the remaining length \r\n    #fibonacci series\r\n    PrintFibonacci(0,1,7-2)<\/code><\/pre>\n<p>Output:<\/p>\n<pre class=\" language-python\"><code class=\" language-python\">For Length 7 \r\n1 1 2 3 5 8\r\n\r\nFor Length 10\r\n1 1 2 3 5 8 13 21 34<\/code><\/pre>\n<p><strong>Explanation of the code:<\/strong><\/p>\n<p>First, we created a function and perform recursion on it. In that function, we accepted the value of the previous 2 Fibonacci numbers to calculate the current Fibonacci number. And we have a length that keeps track of the base case.<\/p>\n<p>For the base case of recursion, we are checking if the length reaches 0. If it does, then we will terminate the recursive call.<\/p>\n<p>In other cases, we are printing the Fibonacci number by adding the previous 2 Fibonacci numbers.<\/p>\n<p>And then we recursively call the function to print the next Fibonacci value by updating the previous 2 values and decrementing the length.<\/p>\n<p>Now let\u2019s visualize the recursive calls of this function with the help of a recursion tree. The length we want printed is 7.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/length-to-be-printed-is-7.png\" alt=\"length-to-be-printed-is-7\" width=\"451\" height=\"130\" \/><\/figure>\n<p>Before the recursive call is made, the main function prints the initial 2 values, 0 and 1. And then it passes these values to the recursive function.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/main-function-prints-the-initial-2-values.-0-and-1.png\" alt=\"main-function-prints-the-initial-2-values.-0-and-1\" width=\"451\" height=\"133\" \/><\/figure>\n<p>The Recursive function is printing the value (0 + 1) and recursively calls with the next updated value.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/Recursive-function-is-printing-the-value--0---1-.png\" alt=\"Recursive-function-is-printing-the-value--0---1-\" width=\"451\" height=\"133\" \/><\/figure>\n<p>Then the recursive function is printing the value\u00a0<strong>(1 + 1)<\/strong>\u00a0and recursively calls with the next updated value.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/printfibonacci-1-2-3-.png\" alt=\"printfibonacci-1-2-3-\" width=\"451\" height=\"133\" \/><\/figure>\n<p>Now the recursive function is printing the value\u00a0<strong>(1 + 2)<\/strong>\u00a0and recursively calls with the next updated value.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/printfibonacci-2-3-2-.png\" alt=\"printfibonacci-2-3-2-\" width=\"451\" height=\"133\" \/><\/figure>\n<p>And then the recursive function is printing the value\u00a0<strong>(2 + 3)<\/strong>\u00a0and recursively calls with the next updated value.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/printfibonacci-3-5-1-.png\" alt=\"printfibonacci-3-5-1-\" width=\"451\" height=\"133\" \/><\/figure>\n<p>Now the recursive function is printing the value\u00a0<strong>(3 + 5)<\/strong>\u00a0and recursively calls with the next updated value.<\/p>\n<figure class=\"kg-card kg-image-card\"><img loading=\"lazy\" decoding=\"async\" class=\"kg-image\" src=\"https:\/\/www.freecodecamp.org\/news\/content\/images\/2022\/04\/printfibonacci-5-8-0-.png\" alt=\"printfibonacci-5-8-0-\" width=\"258\" height=\"129\" \/><\/figure>\n<p>Finally, the last call is made. And the length is 0, so it will terminate the recursive call again and the series is printed on the console.<\/p>\n<h4 style=\"text-align: center;\"><span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;\\&quot;Experience the power of our web development course with a free demo - enroll now!\\&quot;&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1061379,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16777215},&quot;12&quot;:0,&quot;15&quot;:&quot;Roboto, RobotoDraft, Helvetica, Arial, sans-serif&quot;,&quot;16&quot;:10,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/entri.app\/course\/python-programming-course\/\"><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/course\/python-programming-course\/\" target=\"_blank\" rel=\"noopener\">&#8220;Experience the power of our web development course with a free demo &#8211; enroll now!&#8221;<\/a><\/span><\/h4>\n<h4><strong>Related Articles<\/strong><\/h4>\n<div class=\"table-responsive wprt_style_display\">\n<div class=\"table-responsive wprt_style_display\">\n<div class=\"table-responsive wprt_style_display\">\n<div class=\"table-responsive wprt_style_display\">\n<table class=\"table\" dir=\"ltr\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<colgroup>\n<col width=\"329\" \/>\n<col width=\"309\" \/><\/colgroup>\n<tbody>\n<tr>\n<td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Kerala PSC VFA Syllabus&quot;}\" data-sheets-hyperlink=\"https:\/\/entri.app\/blog\/kerala-psc-village-field-assistant-vfa-syllabus-exam-pattern\/\"><strong><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/blog\/program-for-finding-factorial-of-a-number-in-python\/\" target=\"_blank\" rel=\"noopener\">Program for Finding Factorial of a Number in Python<\/a><\/strong><\/td>\n<td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Kerala PSC VFA Mock Test&quot;}\" data-sheets-hyperlink=\"https:\/\/entri.app\/blog\/kerala-psc-vfa-free-mock-test\/\"><strong><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/blog\/why-python-is-used-for-data-science\/\" target=\"_blank\" rel=\"noopener\">Why Python Is Used For Data Science?<\/a><\/strong><\/td>\n<\/tr>\n<tr>\n<td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Kerala PSC VFA Exam Date&quot;}\" data-sheets-hyperlink=\"https:\/\/entri.app\/blog\/kerala-psc-vfa-exam-date\/\"><strong><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/blog\/step-by-step-guide-for-getting-a-job-as-a-python-developer\/\" target=\"_blank\" rel=\"noopener\">Guide for getting a job as a Python Developer<\/a><\/strong><\/td>\n<td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Kerala PSC VFA Video Course&quot;}\"><strong><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/blog\/top-python-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noopener\">Python Advanced Interview Questions and Answers<\/a><\/strong><\/td>\n<\/tr>\n<tr>\n<td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Kerala PSC VFA Application Form&quot;}\" data-sheets-hyperlink=\"https:\/\/entri.app\/blog\/kerala-psc-vfa-apply-online\/\"><strong><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/blog\/python-online-course\/\" target=\"_blank\" rel=\"noopener\">Best Online Python Course with Certificate<\/a><\/strong><\/td>\n<td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Kerala PSC VFA Study Materials&quot;}\" data-sheets-hyperlink=\"https:\/\/entri.app\/blog\/kerala-psc-vfa-study-material\/\"><strong><a class=\"in-cell-link\" href=\"https:\/\/entri.app\/blog\/type-conversion-in-python\/\" target=\"_blank\" rel=\"noopener\">What is Type Conversion in Python?<\/a><\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; In this article, we will learn how to print the Fibonacci sequence in python using two different techniques, iteration and recursion. Before we begin, let&#8217;s first understand some basic terminology. What is the Fibonacci Sequence? The\u00a0Fibonacci Sequence\u00a0is a sequence of numbers in which a given number is the result of adding the 2 numbers [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25543708,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1888],"tags":[],"class_list":["post-25543579","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-python-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Program for Fibonacci Series - Entri Blog<\/title>\n<meta name=\"description\" content=\"Python Program for Fibonacci Series - In this article, we will learn how to print the Fibonacci sequence using two different techniques, iteration and recursion.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program for Fibonacci Series - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Python Program for Fibonacci Series - In this article, we will learn how to print the Fibonacci sequence using two different techniques, iteration and recursion.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-30T10:34:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-27T09:23:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Feeba Mahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Feeba Mahin\" \/>\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:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"Python Program for Fibonacci Series\",\"datePublished\":\"2022-09-30T10:34:16+00:00\",\"dateModified\":\"2023-04-27T09:23:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\"},\"wordCount\":1069,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png\",\"articleSection\":[\"Articles\",\"Python Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\",\"url\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\",\"name\":\"Python Program for Fibonacci Series - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png\",\"datePublished\":\"2022-09-30T10:34:16+00:00\",\"dateModified\":\"2023-04-27T09:23:53+00:00\",\"description\":\"Python Program for Fibonacci Series - In this article, we will learn how to print the Fibonacci sequence using two different techniques, iteration and recursion.\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png\",\"width\":820,\"height\":615,\"caption\":\"Python Program for Fibonacci Series\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/python-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Program for Fibonacci Series\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\",\"name\":\"Feeba Mahin\",\"url\":\"https:\/\/entri.app\/blog\/author\/feeba123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Program for Fibonacci Series - Entri Blog","description":"Python Program for Fibonacci Series - In this article, we will learn how to print the Fibonacci sequence using two different techniques, iteration and recursion.","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:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/","og_locale":"en_US","og_type":"article","og_title":"Python Program for Fibonacci Series - Entri Blog","og_description":"Python Program for Fibonacci Series - In this article, we will learn how to print the Fibonacci sequence using two different techniques, iteration and recursion.","og_url":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-09-30T10:34:16+00:00","article_modified_time":"2023-04-27T09:23:53+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png","type":"image\/png"}],"author":"Feeba Mahin","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Feeba Mahin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"Python Program for Fibonacci Series","datePublished":"2022-09-30T10:34:16+00:00","dateModified":"2023-04-27T09:23:53+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/"},"wordCount":1069,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png","articleSection":["Articles","Python Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/","url":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/","name":"Python Program for Fibonacci Series - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png","datePublished":"2022-09-30T10:34:16+00:00","dateModified":"2023-04-27T09:23:53+00:00","description":"Python Program for Fibonacci Series - In this article, we will learn how to print the Fibonacci sequence using two different techniques, iteration and recursion.","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/09\/Python-Program-for-Fibonacci-Series.png","width":820,"height":615,"caption":"Python Program for Fibonacci Series"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/python-program-for-fibonacci-series\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Programming","item":"https:\/\/entri.app\/blog\/category\/python-programming\/"},{"@type":"ListItem","position":3,"name":"Python Program for Fibonacci Series"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36","name":"Feeba Mahin","url":"https:\/\/entri.app\/blog\/author\/feeba123\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25543579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25543579"}],"version-history":[{"count":8,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25543579\/revisions"}],"predecessor-version":[{"id":25559317,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25543579\/revisions\/25559317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25543708"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25543579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25543579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25543579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}