1.依次修改列表中的值
a = [1,2,3,4] for i in range(len(a)): a[i] = 1 print(a)#[1,1,1,1]
#这样对temp进行更改不行 a = [1,2,3,4] for temp in a: #相当于把值给了temp,对temp进行操作与a无关 temp = 1 print(a)#[1,2,3,4],没有修改值
2.
a = 4 type(a/2) <class 'float'> type(a//2) <class 'int'>
3.int(False) = 0
int(True) = 1
4.多次需要使用数列中的最大值时,先把数列最大值计算出来,再使用。不要每次都使用max(list),当数列长度很长时,这样会浪费很多时间。
5.
a = [True,True,False] sum(a) Out[6]: 2
6
a = 001#报错
int("001")=1