name ="wry smile ss"print(name.capitalize())#首字母大写print(name.count("s"))#统计字符个数print(name.center(50,'-'))#一共打印50个字符不够的用-填补print(name.endswith("ss"))#用什么结尾的print(name.find("ry"))#找符合字符串的第一个下标
name2 ="my name is {name} and age is {age}"print(name2.format(name="Wrysmile",age="22"))#格式化替换print(name2.format_map({"name":"WrySmile","age":22}))#使用字典替换print('abcA123'.isalnum())#是不是阿拉伯数字或者字母print('1'.isdigit())#是不是一个整数print('ass'.isidentifier())#判断是不是一个合法的变量名print("+".join(['1','2','3']))#将列表以+号分开print(name2.ljust(50,"*"))#保证长度为50,不够的用*号填充print(name2.rjust(50,"*"))print('WRySmile'.lower())#将字符串全部改为小写print('WRySmile'.upper())#将字符串全部改为大写print(' WRySmile '.strip())#去掉两边空格
p =str.maketrans("abcdefli","12345#$%")#进行字符替换print("alex li".translate(p))print("alex li".replace('l',"L",1))#字符串替换print("alex li".split())#进行字符串分割 默认为空格print("aLEx li".swapcase())#大小写颠覆
string类型的常用方法name = "wry smile ss"print(name.capitalize())#首字母大写print(name.count("s"))#统计字符个数print(name.center(50,'-'))#一共打印50个字符不够的用-填补print(name.endswith("ss"))#用什么结尾的print(name.find("ry"))#找符合字符串的第一个下标name2 = "my name is {name} and age is {age}"