字符串 str
capitalize
#首字母大寫
test ="will" v = test.capitalize() print(v)

lower() casefold()
# 所有變小寫,casefold(),lower()更常用,很多未知的對應變小寫
test = "wIll" # v1 = test.casefold() # print(v1) v2 = test.lower() print(v2)
center(self, width, fillchar=None)
# self 可以忽略, 有 = 的,None默認值,可帶可不帶,無=的,必須要有值
test = "willwill" v2 = test.count('i',4,5) # count(self, sub, start=None, end=None) # 去字符串中尋找,尋找了序列的出現次數 print(v2)

count(self, sub, start=None, end=None)
# 從開始0往後找,找到第一個之後,獲取其位置
test = "willwill" v = test.find("l",5,8) # 從開始0往後找,找到第一個之後,獲取其位置 # 5<= and <=8 print(v)


endswith(self, suffix, start=None, end=None)
# 從開始0往後找,找到第一個之後,獲取其位置
# 5<= and <=8

find(self, sub, start=None, end=None)
# 從開始0往後找,找到第一個之後,獲取其位置
test = "willwill" v = test.find("l",5,8) # 從開始0往後找,找到第一個之後,獲取其位置 # 5<= and <=8 print(v)

format(self, *args, **kwargs)
# 格式化,將一個字符串中的點位符替換為指定的值
# 根據順序替換 ,必須從0 開始
test = 'i am {0},age {1}' print(test) v = test.format('will',19) # 格式化,將一個字符串中的點位符替換為指定的值 # 根據順序替換 ,必須從0 開始 print(v)


format_map(self, mapping)
# 格式化,傳入的值一定是{'name':'will','a':36}
test ='i am {name}, age {a}' v1 = test.format_map({'name':'will','a':36}) print(v1)

index(self, sub, start=None, end=None)
一般不用
isalnum(self)
# 判斷字符串中是否只包含字母和數字
test = "wasf" v = test.isalnum() # 判斷字符串中是否只包含字母和數字 print(v)

浙公网安备 33010602011771号