Open hug2wisdom opened 4 years ago
list(range(10, 10))
, 返回的是 []
Fibonacci series
def fib(n): # write Fibonzcci series up to n
"""print a Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end = ' ')
a, b = b, a + b
print()
fib(2000)
# result
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
(Yes, this is the correct code. Look closely: the
else
clause belongs to thefor
loop, not theif
statement.)else
不仅仅可以与if
连在一起使用,还可以与for
,try
,while
使用。