成长5 -知识积累

来了!

1、首字母大写capitalize

>>> a='michelle'
>>> a.capitalize()
'Michelle'

2、全变小写casefold

>>> a='Michelle'
>>> a.casefold()
'michelle'

3、居中center,括号里的是空出的长度

>>> a='Michelle'
>>> a.center(15)
'    Michelle   '

4、检验以。。。开头/结尾startwith/endwith

>>> a='Michelle'
>>> a.endswith('l')
False
>>> a.endswith('e')
True

5、查找目标字符的位置

>>> a='Michelle'
>>> a=find('h')
3

6、拆分split

>>> a='Michelle'
>>> a.split('e') ['Mich', 'll', '']
>>> b='you are the best!'
>>> b.split()
['you', 'are', 'the', 'best!']

7、移除开头和结尾的空格和换行符,也可特指,但只是开头或结尾的,所以l 并没有去掉

>>> c='    Michlelle    '
>>> c.strip()
'Michlelle'
>>> a='Michelle'
>>> a.strip('e')
'Michell'
>>> a.strip('l')
'Michelle'

8、合并join,以下命令是将空格和英文单词结合,注意定义时是用列表集合的[ ],print后面要有括号把命令括起来呀~

>>> list=['you','are','the','best']
>>> print(' '.join(list))
you are the best

今天就到这里吧,每天进步一点点,加油!

猜你喜欢

转载自www.cnblogs.com/michellema/p/9761635.html