内置的字符串处理方法
str.lower() | 返回字符串str的副本,全部字符小写 |
---|---|
str.upper() | 返回字符串str的副本,全部字符大写 |
str.islower() | 当str所有字符都是小写时,返回True,否则返回False |
str.isprintable() | 当str所有字符都是可打印的,返回True,否则返回False |
str.isnumeric() | 当str所有字符都是数字时,返回True,否则返回False |
str.isspace() | 当str所有字符都是空格,返回True,否则返回False |
str.endswitch(suffix[,start[,end]]) | str[start:end]以suffix结尾返回True,否则返回False |
str.startswitch(prefix[,start[,end]]) | str[start:end]以prefix开始返回True,否则返回False |
str.split(sep=None,maxsplit=-1) | 返回一个列表,由str根据sep被分隔的部分构成 |
str.count(sub[,start[,end]]) | 返回str[start:end]中sub子串出现的次数 |
str.replace(old,new[,count]) | 返回字符串str的副本,所有old子串被替换为new,如果count给出,则前count次old出现被替换 |
str.center(width[,fillchar]) | 字符串居中函数 |
str.strip([chars]) | 返回字符串str的脚本,在其左侧和右侧去掉chars中列出的字符 |
str.zfill(width) | 返回字符串str的副本,长度为width,不足部分在左侧添0 |
str.format() | 返回字符串str的一种排版模式 |
str.join(iterable) | 返回一个新字符串,由组合数据类型iterable变量的每个元素组成,元素中间使用str分隔 |