建立一个数组:
cast = ["Cleese","Palin","Jones","Idle"]
列出数组有多少数据项:
print(len(cast))
用列表“方法”在末尾增加一个数据项:
cast.append("Gilliam")
用列表“方法”删掉末尾一个数据项:
cast.pop()
用列表“方法”在末尾增加一个数据集合:
cast.extend(["Gilliam","Chapman"])
在列表中找到某个特定数值并删除它:
cast.remove("Jones")
在列表中某个位置前面添加一个数据项:
cast.insert(2,"Jones")
for循环:
for 目标标识符(类似于名称) in 列表:
1 cast = ["Cleese","Palin","Jones","Idle"]
2
3 for i in cast:
4 pirnt (i)
while循环:
使用while循环时,必须要考虑“状态信息”,这就要求使用一个计数标识。
1 cast = ["Cleese","Palin","Jones","Idle"]
2
3 count = 0
4
5 while count < len(cast):
6 print (cast[count])
7
8 count = count+1
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有