String.capitalize() String = "ajj" print(String.capitalize()) 输出:Ajj
String.upper() String = "ajj" print(String.upper()) 输出:AJJ
String.lower() String = "AFjj" print(String.lower() ) 输出:afjj
String.center(输入填充后的总长度,“填充字符串str”) String = "AFjj" print(String.center(10,"*") ) 输出:***AFjj***
string.rjust(输入填充后的总长度,“填充字符串str”) String = "AFjj" print(String.rjust(10,"*") ) 输出:******AFjj
string.ljust(输入填充后的总长度,“填充字符串str”) String = "AFjj" print(String.ljust(10,"*") ) 输出:AFjj******
7.从start到end之间的str次数
String.count(“str”,start,end) #计算string字符串,从所以start,到所以end中“str”字符串的个数 string = "Ajddsadjfj" print(string.count("d",0,-1) ) 输出:3
string.encode(encoding="编码形式utf-8",errors="ignore错误忽略") string.decode(encoding="解码形式utf-8",errors="ignore错误忽略")
string.replace('con','newcon',num) string = "ddsadjfdj" print(string.replace("d","K",3) ) 输出:KKsaKjfdj
string.endswith(“obj”)是否以obj结尾 string = "ddsadjfdj" print(string.endswith("fdj") ) 输出:True
#从左往右找 string.find("str",start,end) #从右往左找 string.rfind("str",start,end)
#从左往右找 string.index(“str”,start,end) #从右往左找 string.rindex(“str”,start,end)
字符串为非空字符串,且每个字符都是字母数字时,返回True,否则返回False string = "a1" print(string.isalnum() ) 输出:True
string.isalpha() string = "akdfkdjf" print(string.isalpha()) 输出:True
string.isdecimal() string = "1021425" print(string.isdecimal()) 输出:True
string.isdigit() string = "102125" print(string.isdigit())
string.islower() #只有当非空字符串全为小写字母,才返回True string = "sdfasd" print(string.islower()) 输出:True
string.isupper() #只有当非空字符串全为大写字母,才返回True string = "HJDF" print(string.isupper()) 输出:True
string.isspace() string = " \n \t" print(string.isspace()) 输出:True
string = "-" csv_str = string.join(['a', 'b', 'c']) print(csv_str) 输出:a-b-c
string.split("str",num) string = "bcdbc" print(string.split("d",1)) 输出:['bc', 'bc']
string = """kdjfkdf fdjsklfj jksdklf """ print(string.splitlines()) 输出:['kdjfkdf', 'fdjsklfj', 'jksdklf']
string.strip("str") #删除string前后的str string = "abdjfjasd" print(string.strip("a")) 输出:bdjfjasd
string.lstrip() string = "abdjfjasa" print(string.lstrip("a")) #删除了左边的字符串a 输出:bdjfjasa
string.rstrip() string = "abdjfjasa" print(string.rstrip("a")) #删除了右边的字符串a 输出:abdjfjas
string.title() string = "we are brother you know" print(string.title()) 输出:We Are Brother You Know