这里我就简单的整理一下Python中字符串的方法,方法太多,后边不想写了,看英文应该知道功能
方法 | 含义 |
capitalize() | 把字符串的第一个字符改为大写 |
casefold() | 把字符串的所有字符改为小写 |
center(width) | 字符串居中,使用空格填充长度为width的新字符串 |
count(sub[,start[,end]]) | 返回sub在字符串中出现的次数,start和end参数为范围 |
endswith(sub[,start[,end]]) | 检查是否以sub结尾 |
expandtabs([tablesize=8]) | 将\t转换为空格,默认为8 |
find(sub[,start[,end]]) | 检测sub是否在字符串中,返回索引 |
index(sub[,start[,end]]) | 跟find一样,不过不存在时会产生异常 |
isalnum() | 所有字符为数字或字母是返回True |
isalpha() | 如果所有字符为字母返回True |
isdecimal() | 如果字符串只包含十进制数字则返回True |
isdigit() | 如果是数字返回True,包括罗马数字、汉字数字 |
islower() | 所有字符都是小写,返回True |
isnumeric() | 如果只包含数字字符,返回True |
isspace() | 如果字符串只包含空格,返回True |
istitle() | 如果所有单词的开头为大写 |
isupper() | 如果所有的字符为大写,返回True |
join(sub) |
|
ljust(width) |
|
lower() |
|
lstrip() |
|
partition(sub) |
|
replace(old,new[,count]) |
|
r find/index/just/partition/strip |
|
split() |
|
title() |
|
translate(table) |
|