简要介绍python的流程和函数
python里面是没有switch的,其实switch是有一个hash表通过表来查找对应的跳转
例如:
switch = {
1:'a',
2:'b',
3:'c',
4:'d'
}
s = [1,2,3,4]
for i in range(1,5) :
print(switch.get(i))
条件判断
a=-1
if a>0:
print(1)
elif a==0:
print(2)
else:
print(3)
循环
for
for i in [1,2,3,4,5]:
print(i)
for i in range(1,10,2):
print(i)
while
i=10
while i>0:
i=i-1
print(i)
函数
def func():
print('this is a function')
func()
函数作为参数传递
def childFunc():
return 1
def fatherFunc(f):
print(f)
fatherFunc(childFunc())