name = "My name is jiachen" #首字母大写print (Name.capitalize ()) #统计字母出现次数print ( Name.count (' a ')) #居中打印print (Name.center (+, '-')) #字符串装换成bytes类型print (Name.encode (' Utf-8 ')) # Judge with what end print (name.endswith (' en ')) #将tab转多少个空格print (Name.expandtabs ()) #查找字符开头索引print (name.find (' Y ')) #格式化字符串 #name = "My name is {name} and i am {year} old" #print (Name.format (name= ' Jiachen ', year=27)) #print (Name.format_map ({' name ': ' Jiachen ', ' Year ': 27}) # Whether the number or letter print (' abc123 '. Isalnum ()) #是否为字母print (' ABC '. Isalpha ()) #是否为十进制print (' 1 '. Isdecimal ()) # Is the integer print (' One '. IsDigit ()) #判断是不是一个合法的表示符 (variable name) print (' A1A '. Isidentifier ()) #是否为小写print (' ABC '). Islower ()) #是否只有数字print (' 213 '. IsNumeric ()) #是否为空格print (' '. Isspace ()) #是否每个首字母大写print (' My name is '. Istitle ()) #是否能打印,tty file drive fileprint (' My name is '). Isprintable ()) #是否都为大写print   (' My '. Isupper ()) #拼接字符串print (' + '. Join (' abc ')) #长50不够用 * Number followed by print (Name.ljust (*)) #长50不够用 * print (Name.rjust ()) #变小写print (' Alex ' lower ()) #变大写print (' Alex '. Upper ()) # Remove the space from the left to enter print (' jiachen '. Lstrip ()) #从右边去掉空格回车print (' jiachen '). Rstrip ()) #去掉头尾空格print (' jiachen '. Strip ()) #p = str.maketrans (' abcdef ', ' 123456 ') ) print (' Jiachen '. Translate (p)) #字符串替换print (' Jaaaiachen '. Replace (' A ', ' X ', 1)) #从右侧查找print (' Jiachen '. RFind (' e ')) #分割成列表print (' Jiachen '. Split (' a ')) #匹配换行符, split into List print (' 1+2\n+3+4 '. Splitlines ()) # Invert case print (' Jiachen '. Swapcase ()) #变成一个titleprint (' Jiachen '. Title ()) #不够50就前面补零print (' Jiachen '). Zfill (50))
This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1896743
Python Route 10-string manipulation