字符串

Posted wrw202

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串相关的知识,希望对你有一定的参考价值。

test = "alex"

v = test.capitalize() #首字母大写

print (v)

v1 = test.casefold()#所有变有小写

print(v1)

v2 = test.lower()

print(v2)

v3 = test.center(20,"#)      

print (v3)  

结果:########alex########

test = "alexalexr"

v4 = test.count(‘e‘)

print (v4)

结果:2

v4 = test.count(‘e‘,5)

结果:1

v5 = test.endswith(‘ex‘)

v6 = test.startswith(‘ex‘)

 

test = "i am {name},{age}"

v = test.format(name=‘alex‘,age=19)

test = "i am [0],[1]"

v = test.format("alex",19")

test = "uasf890"

v = test.isalnum()  #只能字母+数字

 

以上是关于字符串的主要内容,如果未能解决你的问题,请参考以下文章