记得在语句后加冒号
# 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流程控制工具
如对本文有疑问, 点击进行留言回复!!
软件测试工程师学习Python后不得不学的模块-random随机数模块
python练习06_20200809(实现四舍五入&reduce函数)
Django运行服务报NameError: name ‘os‘ is not defined
网友评论