Tuples are very similar
to lists, except that they are immutable (they cannot be changed) and are
created using parentheses (), rather than square brackets. With tuples, we
cannot change elements. This makes programs more predictable. So tuples can be
used as values, unlike classes, they never change.
The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the Tuple statement in Python:
The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the Tuple statement in Python:
Æ’ python command
x = ()
y = ('yo',)
z = ('yo', 'bla')
cars = ('Tesla', 'Porsche', 'Ford',
'BMW', 'Audi')
print(x,y,z,cars)
print(len(cars))
print(cars[1])
√ output
() ('yo',) ('yo', 'bla')
('Tesla', 'Porsche', 'Ford', 'BMW',
'Audi')
5
Porsche
Sign up here with your email

ConversionConversion EmoticonEmoticon