Hi! 大家好,我是Eric,這次教大家Python的流程控制(control flow)!
x = 15
if x == 0:
print(x)
elif x > 0:
print(x)
elif x < 0:
print(x)
else:
print(x)
for N in [2,3,5,7]
print(N, end=" ")
for i in range(10) #迭代器最常用的是range()
print(i, end=" ")
list[range(5,10)]
list[range(0,10,2)]
i = 0
while i < 10:
print(i, end=" ")
i = i + 1
a, b = 0, 1
amax = 100
L = []
while True:
(a, b) = (b, a + b)
if a < amax: #當a=amax時跳出整個迴圈
break
L.append(a)
print(L)
for n in range(20):
if n/2 == 0: #當n/2==0時跳過當次迴圈
continue
print(n, end=" ")