Python3字符串處理函數
Python3
#字符串判斷函數
s = "hello"
# 判斷字符串是否全英文
s.isalpha()
# 判斷全數字或全英文
s.isalnum()
# 判斷是否全數字
s.isdigit()
# 字符串處理函數
# 以什么字符開頭
s.startswith("h")
# 結尾
s.endswith("l")
# 去頭尾空格
s.strip()
# 字符串拼接方式
s+' word'
# 使用join拼接list中的字符串,可指定拼接符號
''.join(s)
# 將字符串轉換成大寫
s.upper()
# 轉換成小寫
s.lower()
# 首字母大寫
s.title()
# 使用string實現首字母大寫
import string
string.capwords(s)
# 字符串切割,切割成list,默認以空字符作為切割符
l = "www.gdkl.top"
l.split(".")
# 字符替換
l.replace("top","com")
# 居中打印
s.center(30)
# 從右邊填充空格
s.ljust(30)
# 左邊
s.rjust(30)