编写一段输出斐波那切数列的Python代码
时间: 2023-05-13 18:04:23 浏览: 115
py代码-斐波那契数列
以下是输出斐波那契数列的Python代码:
```
def fibonacci(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib = [0, 1]
for i in range(2, n):
fib.append(fib[i-1] + fib[i-2])
return fib
print(fibonacci(10))
```
输出结果为:[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
阅读全文