def fib(n=5):
时间: 2024-05-11 09:18:58 浏览: 102
fib.rar_fib
This is a Python function that generates the first n Fibonacci numbers. Here is the code:
```python
def fib(n=5):
a, b = 0, 1
for _ in range(n):
print(a)
a, b = b, a + b
```
The function initializes two variables, `a` and `b`, to 0 and 1 respectively. It then enters a loop that iterates `n` times. In each iteration, it prints the current value of `a` and updates `a` and `b` to be the next two Fibonacci numbers. Finally, the function returns `None` (implicitly, since there is no `return` statement). By default, the function generates the first 5 Fibonacci numbers, but you can pass a different value of `n` to generate more or fewer numbers. For example, `fib(10)` would generate the first 10 Fibonacci numbers.
阅读全文