开始复习2

数据类型:

字符串:

定义:在单引号、双引号、三引号内,由一串字符组成。

name='egon'

需要掌握:

1.索引取值(正向取,反向取)    :只能取

2.切片(顾头不顾尾,步长)

3.长度len

4.成员运算in和not in

5.移除空白strip

6.切分split

7.循环

需要掌握的操作:

1.strip,lstrip,rstrip

2.lower,upper

3.startwith,endwith

4.format的三种玩法

5.split,rsplit

6.join

7.replace

8.isdigit

name = ' egon  '
p = '**zzx***'
print(name.lstrip(' '))
print(p.strip('*'))
print(p.lstrip('*'))
print(p.rstrip('*'))


运行结果:
egon  
zzx
zzx***
**zzx
#lower upper


name = ' eGoN  '
print(name.lower())
print(name.upper())


运行结果:
egon  
EGON 
#startwith,endwith

name = ' eGoN  '
print(name.startswith(' '))
print(name.endswith('N'))

运行结果:
True
False
#format 格式化输出
# res = '{} {} {}'.format('egon','18','male')
# res = '{1} {0} {1}'.format('egon','18','male')
res = 'name:{name}\nsex:{sex}\nage:{age}'.format(sex = 'male',age = 18,name = 'egon')
print(res)


运行结果:
egon 18 male
18 egon 18
name:egon
sex:male
age:18
 

猜你喜欢

转载自www.cnblogs.com/godseven/p/9095471.html
今日推荐