count()
center()
startswith()
find()
format()
lower()
upper()
strip()
replace()
split()
str = ‘hellow python’
str.count(‘l’)#计算单个字符再字符串中的个数,统计元素个数
1
2
2
1
str.capitalize()#字符串的首字母大写
1
‘Hellow python’
1
str.center(50,’’)#居中
1
'hellow python’
1
str.endswith(‘y’)# 看以某个内容结尾
1
False
1
str.startswith(‘he’)
1
True
1
str2 = ‘he\tllow python’
print(str.expandtabs(tabsize=20))
1
2
hellow python
1
str.find(‘p’)#找寻元素返回索引值
1
7
1
str2 = ‘hellow python {boy}’
str2.format(boy = ‘bob’)
1
2
‘hellow python bob’
1
str.index(‘p’)
1
7
1
str3 = ‘123asf’
str3.isalnum()#判断是否有字母字符串
1
2
True
1
str3.isdecimal()#判断是否是十进制的数
1
False
1
str3.isdigit()#判断是否是数字
1
False
1
str3.isnumeric()
1
False
1
str3.isidentifier()#检验是否是非法变量
1
False
1
str3.islower()#判断是否都是小写
1
True
1
str3.isupper()#判断是否都是大写
1
False
1
str.isspace()#判断是否是空格
1
False
1
‘My Python’.istitle()#判断是否是标题的格式
1
True
1
python的内置方式
最新推荐文章于 2023-08-22 14:39:43 发布