字符串 列表、元组、字典

2018-07-21  本文已影响26人  苗_a

索引切片

切片的语法:【起始:结束:步长】

字符串常见操作

1.find


a2003c397f6a0a4388dea3c7c5a99ccc.png

2.、index


Image.png
3.count
Image.png

4.replace


Image.png
5.split
Image.png
6.capitalize
Image.png
7.title
Image.png
8.startswith
Image.png

9.endswith


Image.png
10.lower
Image.png
11.upper
Image.png
12.ljust
Image.png
13.rjust
Image.png
14.center
Image.png
15.lstrip
Image.png
16.rstrip
Image.png
17.strip
Image.png
18.partition
Image.png

19.rpartition


Image.png
21.isalpha
Image.png
22.isdigit
Image.png
23.isalnum
Image.png
24.isspace
Image.png
25.join
Image.png

列表

Image.png

元组

Image.png

字典

Image.png

列表的方法

append添加
extend添加
insert插入
pop删除 两种 按位置
remove按名字删除
del 删除 按位置
sort 升序
sort(rever=True)降序
xxx.rever 倒序

遍历

循环遍历
for i in list:
print(" %s"%i)

统计

长度+len()
count()统计个数
print(max(xxx))
max()最大值
min()最小值
sum()求和

元组

tuple
根据值查索引xxx.index()
统计列表元素的个数xxx.count()

字典

添加
d[xxx] = xxxx
删除
xxx.pop
改[ ]=

print(d[xxxx])

上一篇 下一篇

猜你喜欢

热点阅读