记得在语句后加冒号
# Fibonacci series:
# the sum of two elements defines the next
a, b = 0, 1
while a < 10:
print(a,end=',')
a, b = b, a+b
a < 10
)保持为真就会一直执行x = int(input("Please enter an integer: "))
if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
print('Zero')
elif x == 1:
print('Single')
else:
print('More')
if
... elif
... elif
... 序列可以看作是其他语言中的 switch
或 case
语句的替代words = ['cat', 'window', 'defenestrate']
for w in words:
print(w, len(w))
a = ['Mary', 'had', 'a', 'little', 'lamb']
for i in range(len(a)):
print(i, a[i])
range(5, 10)
5, 6, 7, 8, 9
range(0, 10, 3)
0, 3, 6, 9
range(-10, -100, -30)
-10, -40, -70
def f(arg): pass # a function that does nothing (yet)
class C: pass # a class with no methods (yet
pass是一个空操作 --- 当它被执行时,什么都不发生。 它适合当语法上需要一条语句但并不需要执行任何代码时用来临时占位Python3.7.4入门-2流程控制工具
原文:https://www.cnblogs.com/jestland/p/11585917.html