python使用小记录
查看已安装的包
pip list
安装指定包
pip install [package]
判断类型是否为空
if var is None:
print('None')
print()不换行
print('hell word',end='')
代码换行
print('hell\
o world'\
)
枚举set转成dict
for idx, dur_type in enumerate(durations):
idx2duration[dur_type] = idx
合并list
a = [1,2,3]
b=[3,4,5]
a.extend(b)
a
Out[1324]: [1, 2, 3, 3, 4, 5]
列表中的内容复制n份
[1,2]*5 # [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]