加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python:元组和小括号的误导

发布时间:2020-12-17 01:25:09 所属栏目:Python 来源:网络整理
导读:>> aa[0](12,34)>>> aa[0]=(1,2)Traceback (most recent call last): File " ",line 1,in TypeError: 'tuple' object does not support item assignment>>> aa[0][0]12>>> aa[0][0]=34Traceback (most recent call last): File " ",in TypeError: 'tuple' ob

>> aa[0]
(12,34)
>>> aa[0]=(1,2)
Traceback (most recent call last):
  File "",line 1,in 
TypeError: 'tuple' object does not support item assignment
>>> aa[0][0]
12
>>> aa[0][0]=34
Traceback (most recent call last):
  File "",in 
TypeError: 'tuple' object does not support item assignment

>> pos = {0: (20,20),1: (20,40),2: (40,3: (40,4: (30,30)}
>>> pos
{0: (20,30)}
>>> pos[0]=(1,2)
>>> pos
{0: (1,2),30)}
>>>


>> a = dict(one=1,two=2,three=3)
>>> b = {'one': 1,'two': 2,'three': 3}
>>> c = dict(zip(['one','two','three'],[1,2,3]))
>>> d = dict([('two',('one',1),('three',3)])
>>> e = dict({'three': 3,'one': 1,'two': 2})
>>> a == b == c == d == e
True

>>a=("one","two")
>>>a[0]
'one'
>>>b=("one")
>>>b[0]
'o'
>>>c=("one",)

c[0]
'one'
d="one",>>>d[0]
one

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读