replace() ,strip(),split(),join().函數處理字符串

#replace(old,new,count),old是字符串,new是要替代的字符串,count是次數
list_3 = '張\n三\n\n\n'
s = list_3.replace('\n','')
print(s)
# 張三
 # strip(),是去除首尾兩端的字符串,中間不能去除
list_3 = '張\n三\n\n\n'
s = list_3.strip()
print(s)
'''
張
三
'''
 # split()是分割字符串,()獲得新的列表
b = 's a d f s d'

s = b.split()
print(s)
 # join()是字符串拼接
b = 'sdfert'
s = ' '.join(b)
print(s)
相關文章
相關標籤/搜索