[python] 字符串常用操作


name.capitalize()  首字母大写
name.casefold()   大写全部变小写
name.center(50,"-")  输出 '---------------------Alex Li----------------------'
name.count('lex') 统计 lex出现次数
name.encode()  将字符串编码成bytes格式
name.endswith("Li")  判断字符串是否以 Li结尾
"Alex\tLi".expandtabs(10) 输出'Alex      Li', 将\t转换成多长的空格 
name.find('A')  查找A,找到返回其索引, 找不到返回-1 
msg.index('a')  返回a所在字符串的索引
String.format_map() 将字典中的参数传递进字符串中,输出
'9aA'.isalnum()   True  判断字符串中是否全部为数字或者英文
'9'.isdigit() 是否整数
name.isnumeric  
name.isprintable
name.isspace
name.istitle
name.isupper
 "|".join(['alex','jack','rain'])
'alex|jack|rain'

String.replace(old,new,count) 将字符串中的old字符替换为New字符,count为替换的个数
String.split() 切割

posted @ 2019-05-08 21:34  Moke丶青  阅读(67)  评论(0编辑  收藏  举报