条件判断语句:
if … elif…elif…else…
'''
想最快的入门Python吗?请搜索:"泉小朵",来学习Python最快入门教程。
也可以加入我们的Python学习Q群:902936549,看看前辈们是如何学习的。
'''
中间可以添加更多的elif,它是else if 的缩写,也可以不要,else也可以不添加
循环语句:
For x in a:
A是list类型的或其他的有集合性质的
Else也可以配合for使用,当for循环正常结束后就进入else语句执行,注意else和谁对齐就和谁配对,如下:
y=int(input(“pleaseinput an integer:”))
for x in range(0,10):
if x==y:
print("OK")
break;
else
print(“No”)
如果你输入5就会输出OK,输入一个大于9的数就输出no
函数定义:
Def fname(param):
也可以用name表示多个参数,*name表示字典
形如:def concat(*args,sep=’/’):
ReturnSep.join(args);
如:concat(‘usr’,’application’)会返回’usr/application’
你也可以使用**args作为参数
def parrot(voltage,state='a stiff',action='voom'):
... print("-- Thisparrot wouldn't",action,end=' ')
... print("if youput",voltage,"voltsthrough it.",end=' ')
... print("E's",state,"!")
...
>>> d={"voltage":"fourmillion","state":"bleedin' demised","action":"VOOM"}
>>> parrot(**d)
-- This parrot wouldn't VOOM if you putfour million volts through it. E's bleedin' demised !
Lamba的用法:
如:
def test(x):
return lambda a: a+x+2
b=test(10)
print(b(11))
test(x) 返回的其实是一个函数,这个函数有一个参数a,返回的值就是a+x+2,
x是调用test(x)给出的