>>> quest='what is your favorite color?'
>>> quest.capitalize() #把字符串的第一个字符大写
'What is your favorite color?'
>>> quest.center(40) #返回一个原字符串居中,并使用空格填充至长度width的新字符串
' what is your favorite color? '
>>> quest.count('or') #返回str在string里面出现的次数,如果beg或end指定则返回指定范围内str出现的次数
2
>>> quest.end
>>> quest.endswith('blue') #检查字符串是否已obj介绍,如果beg或end指定则检查指定范围内是否以obj结束
False
>>> quest.endswith('color?')
True
>>> quest.find('or',30) #检查str是否包含在string中,如果beg或end指定则检查指定范围内str是否在string中
-1
>>> quest.find('or',22)
25
>>> quest.index('or',10) #和find()方法一样,只不过如果str不在string中会报一个异常
16
>>> ':'.join(quest.split()) #以str为分隔符切片string,如果num有指定值,则仅分隔num个子字符串
'what:is:your:favorite:color?'
>>> quest.replace('favorite color','quest') #把str1换成str2
'what is your quest?'
>>> quest.upper() #转换成大写
'WHAT IS YOUR FAVORITE COLOR?'
>>> quest.capitalize() #把字符串的第一个字符大写
'What is your favorite color?'
>>> quest.center(40) #返回一个原字符串居中,并使用空格填充至长度width的新字符串
' what is your favorite color? '
>>> quest.count('or') #返回str在string里面出现的次数,如果beg或end指定则返回指定范围内str出现的次数
2
>>> quest.end
>>> quest.endswith('blue') #检查字符串是否已obj介绍,如果beg或end指定则检查指定范围内是否以obj结束
False
>>> quest.endswith('color?')
True
>>> quest.find('or',30) #检查str是否包含在string中,如果beg或end指定则检查指定范围内str是否在string中
-1
>>> quest.find('or',22)
25
>>> quest.index('or',10) #和find()方法一样,只不过如果str不在string中会报一个异常
16
>>> ':'.join(quest.split()) #以str为分隔符切片string,如果num有指定值,则仅分隔num个子字符串
'what:is:your:favorite:color?'
>>> quest.replace('favorite color','quest') #把str1换成str2
'what is your quest?'
>>> quest.upper() #转换成大写
'WHAT IS YOUR FAVORITE COLOR?'