Python之元组 列表 多维列表 字典

本文详细介绍了Python中的数据结构,包括元组的基本用法,如遍历输出元素;列表的操作,如添加、删除元素,获取索引和计数,排序等;多维列表的概念;以及字典的元素增删。通过实例展示了各种操作的具体实现和结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 元组 列表基本用法

将列表或者元组里的元素依次输出:
 

#元组
a_tuple=(1,23,43,5454,656,43)
b_tuple=23,434,5,3,2,3

#列表
a_list=[34,24,'qw',87,3,44,5,23]

for content in a_list:
    print(content)
for content in a_tuple:
    print(content)

输出序号和内容:

#列表
a_list=[34,24,'qw',87,3,44,5,23]

for index in range(len(a_list)):
    print(" the index",index,"number is",a_list[index])

运行结果:

 

D:\PycharmProjects\pythonProject\venv\Scripts\python.exe D:/PycharmProjects/pythonProject/hello.py
 the index 0 number is 34
 the index 1 number is 24
 the index 2 number is qw
 the index 3 number is 87
 the index 4 number is 3
 the index 5 number is 44
 the index 6 number is 5
 the index 7 number is 23

2 列表

添加一个值到列表里:
 

#列表
a_list=[34,24,'qw',87,3,44,5,23]

a_list.append(0)
print(a_list)<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值