The book says that tuples are contained within parentheses and cannot be modified. The list is enclosed in brackets and can be modified.
Lists can be nested lists, tuples can be nested tuples, generally no one mixed, this test is correct:
>>> Aa[0] (aa[0]=) >>> Traceback (most recent): File ' <stdin> ', line 1, in <module>typeerror: ' Tuple ' object does not support item assignment>>> aa[0][0]12>>> aa[0][0]= 34Traceback (most recent): File "<stdin>", line 1, in <module>typeerror: ' Tuple ' object does not Support Item Assignment
However, the dictionary was used during the drawing process, and the value of the tuple was inadvertently modified:
>>> pos = {0: (1), 2: (+, +), 3: (+), 4: (+, +)}>>> pos{0: (20, 20), 1: (20, 2: (+), 3: (+), 4: ()}>>> pos[0]= >>> pos{0: (1, 2), 1: (20, 40), 2: (40, 40), 3: (+), 4: (+)}>>>
This is then found in the dict search of the reference manual:
>>> a = Dict (one=1, two=2, three=3) >>> B = {' One ': 1, ' both ': 2, ' three ': 3}>>> c = dict (Zip ([' O Ne ', ' both ', ' three '], [1, 2, 3]) >>> d = dict ([' One ', 1), (' Three ', 3)]) >>> e = dict ({' thre E ': 3, ' one ': 1, ' both ': 2} ' >>> a = = b = = C = = d = = Etrue
In other words, the value of the value in the dictionary can be modified whether it is enclosed in parentheses, brackets, curly braces, or parentheses.
Another misleading reference is the relationship between tuples and parentheses in Python, where tuples are determined by commas, not parentheses. As you can see, even if you don't have parentheses, you're a tuple.
>>>a= ("One", "one", "one") >>>a[0] ' one ' >>>b= ("one") >>>b[0] ' O ' >>>c= ("one") >>>c[0] ' one ' >>>d= "one", >>>d[0]one
Copyright NOTICE: Welcome reprint, Reprint please indicate the source http://blog.csdn.net/ztf312/
Python: The misleading of tuples and parentheses