Python tuples - tuple datatype in python

python tuples-tuple datatype in python


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])



No comments:

Post a Comment

Latest Post

Don’t Sweat It – Chill with Crompton Air Cooler Deals

 ðŸŒž Don’t Sweat It – Chill with Crompton Air Cooler Deals  More Details : https://www.amazon.in/s?k=laptops+under+70000&crid=29QIFPXQYB3...