1、列表按切片修改
List = ['Wang', [1,2,3,4], 'Liu', 'Xinyouyi', 'zhangsanfeng' ,'王小二'] List[0:2] = '狗屎' print(List) ---------------------------------- ['狗', '屎', 'Liu', 'Xinyouyi', 'zhangsanfeng', '王小二']
List = ['Wang', [1,2,3,4], 'Liu', 'Xinyouyi', 'zhangsanfeng' ,'王小二']
List[0:3] = '狗屎刘旺张'
print(List)
--------------------------------------------
['狗', '屎', '刘', '旺', '张', 'Xinyouyi', 'zhangsanfeng', '王小二']
2、列表循环查询
List = ['Wang', [1,2,3,4], 'Liu', 'Xinyouyi', 'zhangsanfeng' ,'王小二'] for Loop in List: print(Loop)
-----------------------
Wang
[1, 2, 3, 4]
Liu
Xinyouyi
zhangsanfeng
王小二
-----------------------------
List = ['Wang', [1,2,3,4], 'Liu', 'Xinyouyi', 'zhangsanfeng' ,'王小二']
print(List[0:3])
---------------------------
['Wang', [1, 2, 3, 4], 'Liu']
3、列表长度
List = ['Wang', [1,2,3,4], 'Liu', 'Xinyouyi', 'zhangsanfeng' ,'王小二'] L = len(List) print(L)
-----------------
6
4、列表元素统计
List = ['Wang', [1,2,3,4], 'Liu','Liu','Liu','Xinyouyi', 'zhangsanfeng' ,'王小二'] L = List.count('Liu') print(L)
标签:王小二,zhangsanfeng,Python,Day4,List,元组,Liu,Xinyouyi,Wang From: https://www.cnblogs.com/leishu/p/16807308.html