added example for immutability for consistency as in other data structure descriptions (#19260)
Other immutable data structures have examples to show immutability which is missing in tuple description which makes it look inconsistent
This commit is contained in:
committed by
Quincy Larson
parent
e36832b1ca
commit
58bef02dbb
@@ -5,6 +5,12 @@ title: The Tuples
|
|||||||
|
|
||||||
A tuple is a sequence of Python objects. Tuples are immutable which means they cannot be modified after creation, unlike lists.
|
A tuple is a sequence of Python objects. Tuples are immutable which means they cannot be modified after creation, unlike lists.
|
||||||
|
|
||||||
|
>>> tuple = (1,2,3)
|
||||||
|
>>> tuple[1] = 4
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
TypeError: 'tuple' object does not support item assignment
|
||||||
|
|
||||||
**Creation:**
|
**Creation:**
|
||||||
|
|
||||||
An empty `tuple` is created using a pair of round brackets, `()`:
|
An empty `tuple` is created using a pair of round brackets, `()`:
|
||||||
|
Reference in New Issue
Block a user