标签:掌握 tag tar 切片 span with orm 信息 str
字符串
#作用:描述名字,性别,国籍,地址等信息
#定义:在单引号\双引号\三引号内,由一串字符组成
name=‘Matthew‘ #优先掌握的操作: #1、按索引取值(正向取+反向取) :只能取 #2、切片(顾头不顾尾,步长) #3、长度len #4、成员运算in和not in #5、移除空白strip #6、切分split #7、循环
用法实例
#strip
name = ‘**Matthew*‘
print(name.strip(*))
print(name.lstrip(*))
print(name.rstrip(*))
#lower,upper
name = ‘Matthew‘
print(name.lower())
print(name.upper())
#startwith,endwith
name = ‘Matthew‘
print(name.endwith(‘w‘))
print(name.startwith(‘M‘))
#format
res = ‘{},{},{}‘.format(‘Matthew‘,18,‘male‘)
res = ‘{0},{1},{0}‘.format(‘Matthew‘,18,‘male‘)
res = ‘{name},{age},{sex}‘.format(name=‘Matthew‘,age=18,sex=‘male‘)
#split
name = ‘Matthew_male‘
name.split(‘_‘)
#join
tag = ‘‘
print(tag.join({‘Matthew‘,‘say‘,‘hello‘,‘world‘})
#replace
msg = ‘Alex is a boy‘
print(msg.replace(‘boy‘,‘girl‘))
标签:掌握 tag tar 切片 span with orm 信息 str
原文地址:https://www.cnblogs.com/majian1992/p/9775955.html