strip的意思是剝奪。
strip()函數作用是操作字符串。
按一定規則剝奪字符串內容,移除頭尾,不移除中間。
strip([chars])函數參數是字符序列
,注意:字符序列。
1 - strip()不傳參
str = ' helloworld '
print(str.strip())
運行結果:
helloworld
2 - strip()傳一個字符
str = '009876000dfd7647000000'
print(str.strip('0'))
運行結果:
9876000dfd7647
3 - strip()傳一個字符序列
str = '12sdfjladsjfalksdjw12'
print(str.strip('1w2'))
運行結果
sdfjladsjfalksdj
頭尾只要有字符序列內字符,都去掉。