#2 Python Generator example: Fibonacci Sequence in Python | Python Tutorial for Beginners

preview_player
Показать описание
In this video, you will learn how to generate the Fibonacci sequence using generators in Python. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones. In this code, we have defined a generator function called "fibonacci()" which yields the next number in the Fibonacci sequence each time it is called.

We have initialized two variables, "a" and "b", to 0 and 1 respectively, and then used a while loop to generate the next number in the sequence by adding the previous two numbers. The "yield" keyword is used to return the current value of "a" each time the function is called.

We have also used the "enumerate()" function to loop through the first 10 numbers in the sequence and print them. The "break" keyword is used to exit the loop after printing the first 10 numbers.

By the end of this video, you will have a clear understanding of how to use generators to generate the Fibonacci sequence in Python.

If you enjoyed this video, please give it a thumbs up 👍and leave a comment 💬 below. Don't forget to subscribe 🔔to my channel for more Python tutorials like this one.

YouTube Playlists:

You can also follow me on:

Thanks for watching! 🙏**

#coding #codingshorts #codingshortvideo #pythonprogramming #python #pythonbasics #codinglife #yasirbhutta #pythontutorial
Рекомендации по теме