1、capitalize(self)
Convert the first character of a string to uppercase
2、casefold(self)
Returns the string generated by converting all uppercase characters in the string to lowercase
3、center(self, width, fillchar=None)
Returns a string with the specified width centered, fillchar is the filled character, the default is space
4、count(self, sub, start=None, end=None)
Returns the number of occurrences of sub in the string, if start or end is specified, returns the number of occurrences of sub within the specified range
5、encode(self, encoding='utf-8', errors='strict')
Encode the string in the encoding format specified by encoding. If an error occurs, a ValueError exception will be reported by default, unless errors specify 'ignore' or 'replace'
6、endswith(self, suffix, start=None, end=None)
Check whether the string ends with suffix, if start or end is specified, check whether the specified range ends with suffix, if so, return True, otherwise return False
7、expandtabs(self, tabsize=8)
Convert the tab symbols in the string string to spaces, the default number of spaces for the tab symbol is 8
8、find(self, sub, start=None, end=None)
Check if sub is included in the string, if the range start and end are specified, check if it is included in the specified range, if it is included, return the index value of the start, otherwise return -1
9、format(self, *args, **kwargs)
Example: 1. Use positional parameters, pass in a list of positional parameters available *list
1、'my name is {} ,age {}'.format('hoho',18)
2、'my name is {1} ,age {0}'.format(10,'hoho')
3, li = ['hoho', 18]
'my name is {} ,age {}'.format(*li)
2. Use keyword parameters. The value of the keyword parameter must match. You can use a dictionary as the keyword parameter to pass in the value. Add ** before the dictionary.
1、'my name is {name},age is {age}'.format(name='hoho',age=19)
2、hash = {'name':'hoho','age':18}
'my name is {name},age is {age}'.format(**hash)
3. Fill and format, precision and base, use index
10、format_map(self, mapping)
Similar to format(self, *args, **kwargs), except that mapping is a dictionary object.
Example: hash = {'name':'hoho','age': 18}
'my name is {name},age is {age}'.format_map(hash)
11、index(self, sub, start=None, end=None)
跟find()方法一样,只不过如果str不在字符串中会报一个异常.
12、isalnum(self)
如果字符串至少有一个字符并且所有字符都是字母或数字则返 回 True,否则返回 False
13、isalpha(self)
如果字符串至少有一个字符并且所有字符都是字母或汉字则返回 True,否则返回 False
14、isdecimal(self)
如果字符串是否只包含十进制字符返回True,否则返回False。
15、isdigit(self)
如果字符串只包含数字则返回 True 否则返回 False
16、isidentifier(self)
判断字符串是否可为合法的标识符
17、islower(self)
如果字符串中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是小写,则返回 True,否则返回 False
18、isnumeric(self)
如果字符串中只包含数字字符,则返回 True,否则返回 False
19、isprintable(self)
判断是否为可打印字符串,是返回 True,否则返回 False
20、isspace(self)
判断是否为空格,是返回 True,否则返回 False
21、istitle(self)
判断是否首字母大写,其他字母小写,是返回 True,否则返回 False
22、issupper(self)
如果字符串中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是大写,则返回 True,否则返回 False
23、str.join(self, iterable)
以指定字符串str作为分隔符,将 iterable中所有的元素(字符串表示)合并为一个新的字符串,iterable必须是每一个元素是字符串,否则会跑出TypeError异常
24、ljust(self, width, fillchar=None)
返回一个原字符串左对齐,并使用 fillchar 填充至长度 width 的新字符串,fillchar 默认为空格
25、lower(self)
转换字符串中所有大写字符为小写
26、lstrip(self, chars=None)
截掉字符串左边的指定字符chars,默认为空格
27、maketrans(self, *args, **kwargs)
创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标
示例:1、a = 'dobi is a dog'
table = str.maketrans('dobi', 'alph')