Writing idiomatic python

列表解析

生成100个数字

[i for i in range(1, 101)]

数值交换

bad usage in python

temp = a
a = b
b = temp

recommend usage

b, a = a, b

in的使用

data = 1
dataset = {1, 2, 3}
data in dataset
key = 'name'
dataset = {'age': 25, 'name': 'python'}
key in dataset
Comments
Write a Comment