字符串常用操作总结
center(self, width, fillchar=None)
count(self, sub, start=None, end=None)
encode(self,encoding='utf-8', errors='strict')
endswith(self, suffix, start=None, end=None)
find(self, sub, start=None, end=None)
isdigit(self)
replace(self, old, new, count=None)
split(self, sep=None, maxsplit=-1)
strip(self, chars=None)
a = 'hello world' print(a.center(50, '-')) # output: -------------------hello world-------------------- print(a.count('l', 2, -1)) # output: 3 print(a.startswith('h')) # 判断开头字符 print(a.endswith('h')) # 判断结尾字符 print(a.find("l")) # 找到返回所查字符索引 -1为未找到 print("22".isdigit()) # 判断是否是整数 l = ["alex", "black girl", "peiqi"] print("-".join(l)) # 拼接字符串, alex-black girl-peiqi print(a.replace('l', 'L', 2)) # heLLo world