一些數據類型

>>> line = "GOOD, 100, 490.10"
>>> types = [str, int, float]
>>> types
[<type 'str'>, <type 'int'>, <type 'float'>]
>>> line_list = line.split(",")
>>> line_list
['GOOD', ' 100', ' 490.10']
>>> [t(l) for t, l in zip(types, line_list)]
['GOOD', 100, 490.1]

all()和any(), all是全部項都是真纔是true, any有一項是真就是turecode

>>>a = [1,0,0,0]                                                 
>>>any(a)
True
>>>all(a)
False

>>> a = [1,2,3,0]
>>> any(a)
True
>>> all(a)
False
>>> sum(a)
6

list中的reverse()和sort()直接操做列表元素,返回Noneip

相關文章
相關標籤/搜索