text = "hello word" text2 = text.capitalize() print(text2)
text = "Hello Word" text2 = text.casefold() print(text2)
text = "Hello Word" text2 = text.lower() print(text2)
text = "Hello Word" text2 = text.center(20,"空") print(text2)
text = "Hello Word" text2 = text.count(‘l‘,3,4) print(text2)
text = "Hello Word" text2 = text.endswith(‘rd‘,8,10) text3 = text.startswith(‘rd‘,8,10) print(text2) print(text3)
text = "Hello Word" text2 = text.find(‘o‘,5,9) print(text2)
text = "Hello Word" text2 = text.index("H") print(text2)
text = "{Hello} {Word}" text3 = "{}{}" text2 = text.format(Hello=‘no‘,Word=‘no‘) text4 = text3.format(‘no‘,‘no‘) print(text2,text4)
text = "{Hello} {Word}" text2 = text.format_map({"Hello":"no","Word":8}) print(text2)
text = "HelloWord" text2 = text.isalnum() print(text2)
text = "HelloWord" text2 = text.isalpha() print(text2)
text = "Hello\tWord" text2 = text.expandtabs(20) print(text2)
text = "②" text2 = text.isdecimal() text3 = text.isdigit() print(text2,text3)
text = "a1_def" text2 = text.isidentifier() print(text2)
text = "123\t45" text2 = text.isprintable() print(text2)
text = " " text2 = text.isspace() print(text2)
text = "Hello Word" text2 = text.istitle() print(text2)
text = "hello word" text2 = text.title() print(text2)
text = "hello word" text2 = "*".join(text) print(text2)
text = "hello word" text2 = text.ljust(20,"0") text3 = text.rjust(20,"1") print(text2,text3)
text = "hello word" text2 = text.zfill(20) print(text2)
text = "hello word" text2 = text.lower() text3 = text.islower() print(text2,text3)
text = "hello word" text2 = text.upper() text3 = text.isupper() print(text2,text3)
21.1.strip() 去掉字符串两侧的空格
21.2.lstrip() 去掉字符串左侧的空格
21.3.rstrip() 去掉字符串右侧的空格
text = " hello word " text2 = text.lstrip() text3 = text.rstrip() text4 = text.strip() print(text2) print(text3) print(text4)
原文:https://www.cnblogs.com/xonghaizi/p/10644213.html