python学习日记01
1 读取.txt文件
1 with open("./Log.txt", "r") as f: # 打开文件 2 data = f.read()
2 查询字符串中特定字符的个数
特定字符个数 = 字符串名.count('特定字符')
3 查询字符串中特定字符的索引
idx = [r.span() for r in re.finditer('a', 'aaabbbaccda')] >>idx [(0, 1), (1, 2), (2, 3), (6, 7), (10, 11)]
4 将字符串按 特定字符进行切割
str = 'aa bb cc dd ee ff ga' str_clip = str.split(' ') >>str_clip ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'ga']