栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python列表操作

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python列表操作

# 列表 [], 然后里面可以是任何类型的数据 12,23.6,“”,[]
# 列表本质上是一个序列0    1    2    3   4
name_list = ["一", "二", "三", "四", ]
# len 表示列表长度
print((name_list, type(name_list), len(name_list)))
# 1,列表索引查找
print(name_list[0])
print(name_list[1])
print(name_list[2])
print(name_list[3])
print(name_list[4])

# 使用index查找指定的数据 返回指定数据在列表 中的位置
print(name_list.index("三"))
# 在指定的列表范围内查找格林,没有找到则报错
# print(name_list.index("格林,0,2"))
# 2,统计一个元素在 列表中的个数 count
name_list2 = ["1", "2", "3", "4", "5"]
result1 = name_list2.count("2")
result2 = name_list2.count("1")
result3 = name_list2.count("3")
print(result1, result2, result3)
# 3.计算列表长度
print(len(name_list))
print(len(name_list2))

name_list3 = ["a空", "b", "c", "d", "e"]
print("a" in name_list3)
print("f" in name_list3)
print("k" in name_list3)
print("l" in name_list3)
#5.增加一个元素到列表中
name_list3.append("l")
print(name_list3)
#追加一个序列
name_list3.append(["f","k"])
print(name_list3)
#追加一个序列 将学列中的值一个一个加入进去
name_list3.extend(["n","m"])
print(name_list3)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/744735.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号