python基础2,,#strip 去除指


#strip 去除指定字符
#name=‘*egon**‘
#print(name.strip(‘*‘))#去除两端的*
#print(name.lstrip(‘*‘))#去除左端的*
#print(name.rstrip(‘*‘))#去除右端的*

#lower,upper
#print(‘ABC‘.lower())
#print(‘abc‘.upper())

#startswith,endswith 布尔,是否以指定字符开始和结束
#name=‘abc_de‘
#print(name.startswith(‘abc‘))
#print(name.endswith(‘de‘))

#format的三种玩法
#res1=‘{} {} {}‘.format(‘egon‘,18,‘male‘)
#print(res1)
#res2=‘{1} {0} {1}‘.format(‘egon‘,18,‘male‘)
#print(res2)
#res3=‘{name} {age} {sex}‘.format(sex=‘male‘,name=‘egon‘,age=18)
#print(res3)

#split
#name=‘1,2,3,4‘
#print(name.split(‘,‘)) #默认分隔符为空格[‘1‘, ‘2‘, ‘3‘, ‘4‘]
#print(name.split(‘,‘,1))#只分隔第一个逗号[‘1‘, ‘2,3,4‘]
参考:http://www.cnblogs.com/linhaifeng/articles/7133357.html

python基础2

评论关闭