2019年3月9日 解压序列
l=[1,2,3,3,4,6,7,5] a,*b,c=l print(a,b,c)
>>1 [2, 3, 3, 4, 6, 7] 5
a,b,c,d,*e='hello' print(a,b,c,d,e)
>>h e l l ['o']
x=3 y=4 x,y=y,x print(x,y)
x,y值互换
def idf(func):#验证登入信息是否正确 装饰器函数 def wrapper(*args,**kwargs): username=input('please input username: '.strip())#.strip指的是移除前后空格或者制表符 password=input('pleasr input password: '.strip()) if username=='sxj' and password=='abc': print("验证通过") res = func(*args, **kwargs) return res else: print('I am sorry') return wrapper @idf def index(): print('welcome to index') @idf def home(name): print('%s,welcome to home'%name) @idf def shopping_car(): print('this is shopping car,you have %s,%s,%s'%('奶茶','妹妹','sxj')) home('sxj') shopping_car()
>>>
please input username:sxj
pleasr input password:abc
验证通过
sxj,welcome to home
please input username:sxj
pleasr input password:abc
验证通过
this is shopping car,you have 奶茶,妹妹,sxj