字符串的首字母大写
str.capitalize()
s = 'hello world'
print(s.capitalize())
# 输出结果:
Hello world
字符串的每个单词首字母大写
str.title()
s = 'hello world'
print(s.title())
# 输出结果:
Hello World
带is
表示判断字符串的每个单词首字母是否是大写Ture
或False
str.istitle()
s = 'hello world'
print(s.istitle(), s)
s_title = s.title()
print(s_title.istitle(), s_title)
# 输出结果:
False hello world
True Hello World
将字符串里的每个字符都大写
str.upper()
s = 'hello world'
print(s.upper())
# 输出结果
HELLO WORLD
将字符串里的字母全部转成小写
str.lower()
s = 'HELLO WORLD'
print(s.lower())
# 输出结果
hello world
求字符串长度的函数
len(str)
s = 'hello world'
print(len(s))
# 输出结果
11
查找
rfind从右往左查找,find从左往右查找
find()
s = 'hello world'
print