首页 > 编程 > Python > 正文

Python中的元组和列表的区别

2019-11-10 17:54:05
字体:
来源:转载
供稿:网友

python中元组用小括号而列表用中括号。 但是元组不能修改值。 实验代码如下:

a=(1,3,4,2)b=[1,2,3,4]b[1]=5PRint(b)a[1]=5print(a)

实验结果:

[1, 5, 3, 4] a[1]=5TypeError: 'tuple' object does not support item assignment
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表