987432340
12/10/2018 - 2:01 PM

python字符串操作

strip replace


# 移除字符串头尾指定的字符
str = "123abcrunoob321"
print (str.strip( '12' ))  # 字符序列为 12

#输出
#3abcrunoob3

#常用 strip("\n") 去除文件首尾的换行符

# 替换字符串
s = "Enter string"
s.replace(" ","+")
# Out[147]: 'Enter+string'