1 字符串
1.1 分割
a = "hhh][jjj"
content = a.split("[[")
# 输出的content为 ['hhh', 'jjj']
1.2 替换
a = "hhhjjj"
content = content.replace("][", '')
# 输出的content为 "hhhjjj"
1.3 提取
str='chengdu'
print(str) # 输出字符串 'chengdu'
print(str[0:-1]) # 输出第一个到倒数第二个的所有字符 'chengd'
print(str[0]) # 输出字符串第一个字符 'c'
print(str[2:5]) # 输出从第三个开始到第五个的字符 'eng'
print(str[2:]) # 输出从第三个开始后的所有字符 'engdu'
print(str * 2) # 输出字符串两次 'chengduchengdu'
print(str[:5]) # 输出第五个字母前的所有字符 'cheng'
print(str[0:7:2]) # [起始:终止:步长] 'cegu'
2 列表
2.1 增加
# append用法,末尾添加
Alldata = ['2','2']
Tdata = '5'
Alldata.append(Tdata)
# 输出Alldata为 ['2', '2','5']
# insert用法,列表某指定位置插入
Alldata = [['NBPY-000','2022-03-17-22:47:19_0_000'],['NBPY-001','2022-03-17-22:47:19_0_000'],['NBPY-002','2022-03-17-22:47:19_0_001'],['NBPY-003','2022-03-17-22:47:19_0_001']]
UseT = '2022-03-17-22:47:19_1_001'
Alldata[1].insert(len(Alldata[1])+1,UseT)
# 输出Alldata为 [['NBPY-000', '2022-03-17-22:47:19_0_000'], ['NBPY-001', '2022-03-17-22:47:19_0_000', '2022-03-17-22:47:19_1_001'], ['NBPY-002', '2022-03-17-22:47:19_0_001'], ['NBPY-003', '2022-03-17-22:47:19_0_001']]
Alldata.insert(2,UseT)
# 输出Alldata为 [['NBPY-000', '2022-03-17-22:47:19_0_000'], ['NBPY-001', '2022-03-17-22:47:19_0_000', '2022-03-17-22:47:19_1_001'], '2022-03-17-22:47:19_1_001', ['NBPY-002', '2022-03-17-22:47:19_0_001'], ['NBPY-003', '2022-03-17-22:47:19_0_001']]