Explanation:
1. Initialization:
a, b = 0, 1 → We start with two variables:
a = 0 (first Fibonacci number)
b = 1 (second Fibonacci number)
a = 0 (first Fibonacci number)
b = 1 (second Fibonacci number)
2. Loop:
for _ in range(3): → Repeat the following 3 times. _ is just a placeholder since we don’t use the index.
3. Printing the current number:
print(a, end=" ") → Prints the current value of a on the same line with a space.
4. Updating the numbers:
a, b = b, a + b → Updates both variables simultaneously:
a becomes the old value of b
b becomes the sum of old a + b (next Fibonacci number)
a, b = b, a + b → Updates both variables simultaneously:
a becomes the old value of b
b becomes the sum of old a + b (next Fibonacci number)
5. Final Output:
0 1 1
Key Concept:
This uses tuple unpacking (a, b = b, a + b) to update two variables simultaneously without a temporary variable, which is a common Python trick for generating sequences like Fibonacci.
.png)

0 Comments:
Post a Comment