xxxxxxxxxx
pythonCopy>>> x = ("Python")
>>> print(type(x))
<class 'str'>
xxxxxxxxxx
x = tuple([3,4,5])
y = 3,4,5
print(x)
# (3, 4, 5)
print(y)
# (3, 4, 5)
print(x == y)
# True
xxxxxxxxxx
pythonCopy>>> x = (3, 'pink', 3+8j)
>>> print('x[0] =', x[0])
x[0] = 3
>>> print('x[0:2] =', x[0:2])
x[0:2] = (3, 'pink')
>>> x[0] = 4
TypeError: 'tuple' object does not support item assignment
xxxxxxxxxx
# Different types of tuples
# Empty tuple
my_tuple = ()
print(my_tuple)
# Tuple having integers
my_tuple = (1, 2, 3)
print(my_tuple)
# tuple with mixed datatypes
my_tuple = (1, "Hello", 3.4)
print(my_tuple)
# nested tuple
my_tuple = ("mouse", [8, 4, 6], (1, 2, 3))
print(my_tuple)
xxxxxxxxxx
car = ("Ford", "Raptor", 2019, "Red")
print(car)
# Length
print(len(car))
# Indexing
print(car[1])
# Slicing
print(car[2:])