In [1]: str = 'hello'
In [2]: str.capitalize()
Out[2]: 'Hello'
In [3]: str.center(20)
Out[3]: ' hello '
In [4]: str = 'sdsadsdasda'
In [5]: str.count('a')
Out[5]: 3
In [6]: str = 'hello'
In [7]: str.encode('utf-8').decode('utf-8')
Out[7]: 'hello'
str.startswith(判断是否以obj开始)
如果是,返回true;否则返回false
In [8]: str
Out[8]: 'hello'
In [9]: str.endswith('o')
Out[9]: True
In [10]: str.endswith('a')
Out[10]: False
在返回索引值(第一次出现),不在返回-1
In [13]: str
Out[13]: 'hello'
In [14]: str.find('a')
Out[14]: -1
In [15]: str.find('l')
Out[15]: 2
string.index(str, beg=0, end=len(string)):不在会报错
In [16]: '{} {}'.format('hello', 'world')
Out[16]: 'hello world'
In [19]: str
Out[19]: 'hello'
In [20]: str.isalnum()
Out[20]: True
In [21]: str = 'hello,'
In [22]: str.isalnum()
Out[22]: False
In [25]: str = 'HELLO'
In [26]: str.casefold
Out[26]: <function str.casefold()>
In [27]: str.casefold()
Out[27]: 'hello'
本文地址:https://blog.csdn.net/gklcsdn/article/details/107082307
如对本文有疑问, 点击进行留言回复!!
网友评论