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…
参考,搬运 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.…