capitalize() | The first character of the string to uppercase |
casefold() | All the characters in the entire string to lowercase |
center(width) | String center, and padded with spaces to the width of the new string length |
count(sub[,start[,end]]) | Returns the number of sub occurring inside the string, start and end parameters indicates a range, optional. |
encode(encoding='utf-8', errors='strict') | To encoding specified encoding format for encoding strings. |
endswith(sub[,start[,end]]) | Check whether the string sub substring end, a return True, otherwise False. parameter indicates the start and end range, optional. |
expandtabs([tabsize=8]) | The tab character string (\ t) are converted to spaces, if not specified, the default is the number of spaces tabsize = 8. |
find(sub[,start[,end]]) | Detecting whether the sub contained in the string, if the index value is returned, otherwise -1, start and end parameters indicates a range, optional. |
index(sub[,start[,end]]) | Like find methods, but not if the sub string will produce an exception. |
isalnum () | If there is at least one character string and all the characters are letters or numbers it returns True, otherwise False. |
Islf () | If there is at least one character string and all the characters are the letters return True, otherwise False. |
isdecimal() | If the string contains only decimal digits returns True, otherwise False. |
isdigit () | If the string contains only digit returns True, otherwise False. |
islower() | These characters If the string contains at least one of alphanumeric characters, and all lowercase, True is returned, otherwise it returns False. |
isnumeric() | If the string contains only numeric characters, it returns True, otherwise False. |
isspace() | If the string contains only spaces, returns True, otherwise False. |
istitl A () | If the string is the title (all the words are in uppercase began rest of the letters are in lower case), then returns True, otherwise False. |
isupper() | If the string contains at least one case sensitive characters, and these characters are uppercase, True is returned, otherwise it returns False. |
join(sub) | String as a separator interposed between all of the characters in the sub. |
light (width) | Returns a string left-aligned and padded with spaces to the width of the length of the new string. |
lower() | Convert a string to all uppercase characters to lowercase. |
lstrip() | Remove all of the strings of spaces left |
partition(sub) | Found sub substring, the string into a 3-tuple (pre_sub, sub, fol_sub), if the string is not included in the sub returns ( 'original string', '', '') |
replace(old,new[,count]) | Replace the old sub-string to string new substring, if the count is specified, alternatively no more than count times. |
rfind(sub[,start[,end]]) | Similar to the find () method, but is beginning to find the right. |
rindex(sub[,start[,end]]) | Similar to the index () method, but starting from the right. |
rjust(width) | Returns a string right justified and padded with spaces to the width of the length of the new string. |
rpartition(sub) | Similar to the partition () method, but is beginning to find the right. |
rstrip() | Remove spaces at the end of the string. |
split(sep=None, maxsplit=-1) | The list is not the default parameters spliced substring after the separator to space string sections, if maxsplit parameters set, only the partition maxsplit substrings, returns slice. |
split lines (([notch ends])) | 按照‘\n’分隔,返回一个包含各行作为元素的列表,如果keepends参数指定,则返回前keepends行。 |
startswith(prefix[,start[,end]]) | 检查字符串是否以prefix开头,是则返回True,否则返回False。start和end参数可以指定范围检查,可选。 |
strip([chars]) | 删除字符串前边和后边所有的空格,chars参数可以定制删除的字符,可选。 |
swapcase() | 翻转字符串中的大小写。 |
title() | 返回标题化(所有的单词都是以大写开始,其余字母均小写)的字符串。 |
translate(table) | 根据table的规则(可以由str.maketrans(‘a’,‘b’)定制)转换字符串中的字符。 |
upper() | 转换字符串中的所有小写字符为大写。 |
zfill(width) | 返回长度为width的字符串,原字符串右对齐,前边用0填充。 |
字符串格式化符号含义及转义字符含义:
字符串格式化符号含义
符 号 | 说 明 |
%c | 格式化字符及其ASCII码 |
%s | 格式化字符串 |
%d | 格式化整数 |
%o | 格式化无符号八进制数 |
%x | 格式化无符号十六进制数 |
%X | 格式化无符号十六进制数(大写) |
%f | 格式化定点数,可指定小数点后的精度 |
%e | 用科学计数法格式化定点数 |
%E | 作用同%e,用科学计数法格式化定点数 |
%g | 根据值的大小决定使用%f活%e |
%G | 作用同%g,根据值的大小决定使用%f或者%E |
格式化操作符辅助指令
符 号 | 说 明 |
m.n | m是显示的最小总宽度,n是小数点后的位数 |
- | 用于左对齐 |
+ | 在正数前面显示加号(+) |
# | 在八进制数前面显示 '0o',在十六进制数前面显示 '0x' 或 '0X' |
0 | 显示的数字前面填充 '0' 取代空格 |
字符串转义字符含义
符 号 | 说 明 |
\' | 单引号 |
\" | 双引号 |
\a | 发出系统响铃声 |
\b | 退格符 |
\n | 换行符 |
\t | 横向制表符(TAB) |
\v | 纵向制表符 |
\r | 回车符 |
\f | 换页符 |
\o | 八进制数代表的字符 |
\x | 十六进制数代表的字符 |
\0 | 表示一个空字符 |
\\ | 反斜杠 |