1. 程式人生 > >python中strip()方法學習筆記

python中strip()方法學習筆記

bbb 方法學 python pytho ring strip strip() clas ng2

Python strip() 方法用於移除字符串頭尾指定的字符(默認為空格)。

當使用strip(‘xxx‘),只要字符串頭尾有"xxx"中的一個,就會去掉,而不是符合字符串‘‘xxx‘‘才去掉

1 >>> string = aaabbbccc
2 >>> string.strip(abc)
3 ‘‘
4 >>> string2 = aaaffbbcc
5 >>> string2.strip(abc)
6 ff
7 >>> string3 = aaaffbbffcc
8 >>> string3.strip(
abc) 9 ffbbff

python中strip()方法學習筆記