字符串1
①string.capitalize() 首字母大写
test='angel'
v=test.capitalize()
print(v)
返回值为:Angel
②string.center(width,fillchar=None) 字符居中并默认用空格填充
test='angel'
v=test.center(20)
print(v)
返回值为: angel (有空格)
test='angel'
v=test.center(20,'-')
print(v)
返回值为:-------angel--------
③string.count(str,beg=0,end=len(string)) string中出现str的次数,默认从头开始到结尾
test='angel'
v=test.count('a')
print(v)
返回值为:1
test='angel'
v=test.count('a',1,2)
print(v)
返回值为:0
值得一提:Python中区间是左闭右开
④string.endswith(obj,beg=0,end=leng(string)) 检查字符是否已obj结束,默认从头开始到结尾
test='angel'
v=test.endswith('el')
print(v)
返回值为:Ture
⑤string.find(str,beg=0,end=len(string))检测sring中第一个str的位置,默认从开始到结尾
test='angel'
v=test.find('e')
print(v)
⑥string.fromat() 格式化字符串,
test='{angel}'
v=test.format(angel='devil')
print(v)
输出值为:devil
⑦string.isalnum() 检测字符串中是否全为字母或数字
⑧string.isalpha() 检测字符串中是否全为字母或汉字
⑨string.islower() 检测字符串中是否全为小写
⑩sring.isnumeric() 检测字符串中是否全为数字
以上内容仅供参考.
菜鸟路过,大神勿喷.

浙公网安备 33010602011771号