python basis - Ganso

Neuron progenitor neuron progenitor tuple can be changed only read the list of tuples stored inside / dictionary (variable type object) can be changed to

Is defined: a = ()


>>>  type (A) # view type
<class 'tuple'>
>>>  the isinstance (A, tuple) # determines whether neuron progenitor
True
>>> # A = 1,2 parentheses may not be automatically converted into tuples
> type >> (a)
<class 'tuple'>
>>> a = (. 1) # is only one element of type int
>>> type (a)
<class 'int'>
>>> a = (. 1,) # put only one element of Ganso must be added a comma

1. Charles

Example: the value Ganso

A = >>> (1,2, [4,5,6])
>>> A
(. 1, 2, [. 4,. 5,. 6])
>>> A [2] [0] # nesting value
4
>>>

Traversal Ganso

Traversed by value

>>> for i in a:
...     print(i)
...
1
2
[4, 5, 6]
>>>

Press coordinates traversal

>>> a=(1, 2, [3, 4, 5, 6])

>>> for i in range(len(a)):
... print(a[i],end=' ')
...
1 2 [3, 4, 5, 6]

>>>

 

2. The only change by the value of the variable target neuron progenitor

>>> a=(1,2,[3,4,5])
>>> a[2].append(6)
>>> a
(1, 2, [3, 4, 5, 6])

>>> a.append(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'append'

Guess you like

Origin www.cnblogs.com/wenm1128/p/11592323.html