__slots__是在python 2.2开始引入的一个新特性, 我们来看一下官方给出的解释. This class variable can be assigned a string, iterable, or sequence of strings with variable names used by instances. If defined in a new-style class, __slots__ reserves space for the declared variables…
1. cities = ['Marseille', 'Amsterdam', 'New York', 'Londom'] # the good way for i, city in enumerate(cities): print(i, city) 2. x_list = [1, 2, 3] y_list = [2, 4, 6] # the good way for x, y in zip(x_list, y_list): print (x, y) 3. x = 10 y = -10 # the…
每个人在使用python的过程中都会遍历list和dict. List遍历 最常用最简单的遍历list的方法 a = ["a", "b", "c", "d"] # simple iterate for i in a: print i 但是, 如果我需要拿到list的index, 很多人可能会这样写 a = ["a", "b", "c", "d"]…