1、python 三元运算符
无,用 if else
2、python 设置代码缩进
全选。。然后按tab
3、记录程序运行时间
import time time_start=time.time() time_end=time.time() print('totally cost',time_end-time_start)
4、python 字符串拼接
join()
5、python 按行读文本文件,并解决文件名包含中文问题
def readLines(fileName): uipath = unicode(fileName, "utf8") print uipath with open(uipath,'r') as file_object: contents = file_object.readlines() return contents
6、python 字符串分隔
[]=“xxx.yyy.zzz”.split()
7、remove 某字符
item=item.replace('/','')
8、字符串包含
index()>-1,不包含时会有异常
find(),功能相同,但不包含时不会有异常