str = 'Hello'
#1、首字母变大写
str.capitalize() #首字母变大写: Hello
#2、内容居中
str.center(30, '=') #内容居中: ============Hello=============
#3、子序列的个数(字母在字符串中出现了几次)
str.count('l') #子序列的个数: 2
#4、是否已什么结尾
str.endswith('o') #是否已什么结尾: True
#5、是否已什么开始
str.startswith('H') #是否已什么开始: True
#6、处理tab键
str2 = 'Hello\t999'str2.expandtabs()#处理tab键: Hello 999
#7、寻找子序列位置,没有找到返回-1,返回了是1
str.find('a') #寻找子序列位置: -1
#8、寻找子序列的位置,没有找到就报错
str.index('e') #寻找子序列的位置: 1
#9、判断是否是字母和数字
str.isalnum() #判断是否是字母和数字: True
#10、判断是否是字母
str.isalpha() #判断是否是字母: True
#11、判断是否是数字
str.isdigit() #判断是否是数字: False
#12、判断是否小写
str.islower() #判断是否小写: False
#13、判断是否有空格
str.isspace() #判断是否有空格: False
#14、判断是否是大写
str.isupper() #判断是否是大写: False
#15、判断是否是标题-->首字母大写,可以理解为大写
str.istitle() #判断是否是标题-->首字母大写: True
#16、 移除左側空格
s4 = 'hello'
print("移除左側空格:", s4.lstrip()) #移除左側空格: hello
#17、移除右边空格
s5 = 'world's5.rstrip()#移除右边空格: world
#18、字符串变小写
str.lower() #字符串变小写: hello
#19、分割字符串,分割后就是元组
s = 'qingbaobei is python's.partition('is') #分割字符串,分割后就是元组: ('qingbaobei ', 'is', ' python')
#20、rfind()从右向左找
s.rfind('qingbaobei') #rfind()从右向左找: 0