参考,搬运 http://python-web-guide.readthedocs.io/zh/latest/idiom/idiom.html 待定 1. Python支持链式比较 # bad a = 5 if a > 1 and a < 7: pass # good if 1 < a < 7: pass 2. Python交换变量 # bad x = 10 y = 5 tmp = x x = y y = tmp # good x = 10 y = 5 x, y = y, x 3.…
1.交换赋值 #不推荐 temp = a a = b b = a #推荐 a , b = b , a #先生成一个元组(tuple)对象,然后在unpack 2.Unpacking #不推荐 l = ['David' , 'Pythonista' , '+1-514-555-1234'] first_name = l[0] last_name = l[1] phone_number = l[2] #推荐 l = ['David' , 'Pythonista' , '+1-514-555-1234…
#####################喜欢就多多关注哦######################### Python初学者的一些编程技巧 交换变量 ? 1 2 3 4 5 6 7 8 9 x = 6 y = 5 x, y = y, x print x >>> 5 print y >>> 6 if 语句在行内 ? 1 2 print "Hello" if True else "World" >>&…