2016年12月29日 星期四

Python 字串處理

切割字串
s='0123456789'
->
s[5:]=56789
s[-2:]=89
s[:5]=01234
s[:-2]=01234567
s[7:9]=78
s[2:10:2]=2468
s[::-1]=9876543210 #反轉字串

切割字元
以','進行分割
str.split(',')
以','串接
','.join(list)

取代
str.replace('原始','取代')

其他
str.find('')

刪除字串前後定字元(預設空白)
str.strip()

沒有留言:

張貼留言