Python tuples Function

Python tuples is a sequence data type, similiar to list and string.

>>> x = (6,9,"website","xyz",[1,2,3])
>>> x[2]
'website'
>>> x
(6,9,'website','xyz',[1,2,3])
>>> y = (x,2,3)
>>> y
((6,9,'website','xyz',[1,2,3]),2,3)
>>> len(x)
5
>>> len(y) #x is an element of y
3
Assign tuples element to multiple variables:
>>> a,b,c = y
>>> a
(6,9,'website','xyz',[1,2,3])
>>> b
2
>>> c
3
tuples are immutable, you can not assign values to tuples elements:
>>> x[2] = 5
Traceback (most recent call last):
File "", line 1, in 
TypeError: 'tuple' object does not support item assignment




endmemo.com © 2024  | Terms of Use | Privacy | Home