找到我就是缘分,为技术一起努力!
格式符
#
price_width = 10
item_width = width - price_width
header_format = '%-*s%*s'
format = '%-*s%*.2f'
print '=' * width
print header_format % (item_width, 'Item', price_width, 'Price')
print '-' * width
print format % (item_width,'Apples',price_width,0.4)
print format %(item_width,'Pears', price_width,0.5)
print format %(item_width,'Cantaloupes',price_width,1.92)
find(str,start,end):从start开始end结束寻找与str相匹配的字符,找到返回匹配项index,找不到返回-1
a='With a moo-moo here. and a moo-moo there'.find('moo',7)
>>> print(a)
7
>>> a='With a moo-moo here. and a moo-moo there'.find('moo',1,8)
>>> print(a)
-1
join():在字符序列之间加入分隔符
>>> seq = ['1','2','3','4','5']
>>> sep
'+'
>>> sep.join(seq)
'1+2+3+4+5'
lower():全部转为小写
>>> 'ZDF'.lower()
'zdf'
title():首字母大写
>>> 'zdf'.title()
'Zdf'
replace(oldstr , newstr):替换字符
>>> 'zdf is a clever boy!'.replace('clever','handsome')
'zdf is a handsome boy!'
split(/PATTERN):以模式来分割,模式的意思就是REGEX
>>> 'zdf+zdf+zdf'.split('+')
['zdf', 'zdf', 'zdf']
strip():去除两侧空格(不包括内部的)
>>> ' zdf '.strip()
'zdf'
strip('*'):也可指定去除两侧特定的字符 ,如*
>>> '*********zdf****************'.strip('*')
'zdf'
网友评论