Python program to print Fibonacci series

Description: Write a Python program to print the first 10 numbers of the Fibonacci series.

Rules and hints:

  • Each number is the sum of the two numbers before it.
  • The series starts with 0 and 1.

Python program for Fibonacci series

a, b = 0, 1

for _ in range(10):
    print(a, end=" ")
    a, b = b, a + b

Output:

Tutorials Class - Output Window

0 1 1 2 3 5 8 13 21 34

How it works

  • a and b hold two neighbour numbers of the series.
  • print(a, end=" ") prints on the same line with a space.
  • a, b = b, a + b moves to the next pair at once.
  • The loop variable _ means we do not use its value.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.