Home Coding Tuple

Tuple

0
Tuple

 
 
# Today we will touch touples.
# Tuples are similar, but they differ in the following properties:
# Tuples are defined by enclosing the elements in parentheses ()
# Tuples are immutable.
#
# Let's create a tuple
tup1 = ("foo", "bar", "ret", "wic")
# With the id function, we get the memory address of an object
id1 = id(tup1)
# Let's try to change the tup1 tuple
# It's not possible to change a tuple once it is created.
# Python will create a new tuple if you try to add new values.
# At the same time is not possible to change any item inside a tuple.
tup1 = tup1 + ("san", "cla")
# Inspect again the memory address
id2 = id(tup1)

OUT = tup1. id1, id2