如何在Python中将字符串中的制表符扩展到多个空格?
Pyhton在字符串类中有一个称为replace的方法。它以要替换的字符串和要替换的字符串作为输入。在字符串对象上调用它。您可以通过以下方式调用此方法以用空格替换制表符:
print( 'replace tabs in this string'.replace('\t', ''))输出值
replace tabs in this string
python中的're'模块也可以使用正则表达式来获得相同的结果。re.sub(regex_to_replace,regex_to_replace_with,string)可用于替换字符串中的字符。例如,
import re
print(re.sub('\t', '', 'replace tabs in this string'))输出值
replace tabs in this string
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短