python中re库的sub()方法
re.sub(pattern, repl, string, count=0, flags=0)
- pattern : 正则中的模式字符串。
- repl : 替换的字符串,也可为一个函数。
- string : 要被查找替换的原始字符串。
- count : 模式匹配后替换的最大次数,默认 0 表示替换所有的匹配。
import re
a_list=[[1.0,2.0],1,2]
print(a_list)
print(a_list[0])
string = str(a_list).replace('[','').replace(']','')
print(str(a_list[0]))
print(string)
输出
[[1.0, 2.0], 1, 2]
[1.0, 2.0]
[1.0, 2.0]
1.0, 2.0, 1, 2