Python tuples - tuple datatype in python
python tuples are ordered it can store variables of all types that are unchangeable
creating tuple in two ways
using parenthesis()
A tuple is created by enclosing comma separated elements inside rounded brackets.
python tuple characteristics:
Ordered : tuples are part of sequence data types
Unchangeable : tuple are unchangeble, we cannot add or delete element
Heterogeneous : means different datatypes
Create a tuple using the two ways:
#Using parenthesis ()
tuple=(56,77,88,78,23)
print(tuple)
print(type(tuple))
output :
(56,77,88,78,23)
#Using a tuple() constructor
x=tuple((56,88,99,34.77,83))
print(x)
print(type(x))
output:
((56,88,99,34.77,83))
#Heterogeneous type tuple elements and nested tuple
sampletuple = ('ram',44,45.65,[23,25, 78])
print(sampletuple)
output:
('ram',44,45.65,[23,25, 78])
Comments
Post a Comment