Tuples in Python
Last updated Aug 08, 2021Tuple
Just like lists, Tuple is also an ordered sequence of similar items but Tuples are Immutable in nature. Tuples are sequences, just like lists. Tuples are also a built-in data type. We cannot modify a tuple once it is created and it is always written in Parenthesis(). Creating a tuple is as simple as putting different comma-separated values.
Let's take an example of Tuple to understand it better:-
a = (10, 20, 30, 40, 50) print(a)
(10, 20, 30, 40, 50) |
So you can see that a tuple is printed.
Let's take a similar example like lists with the use of string slicing:-
my_tuple = ('h','e','l','l','o') print(my_tuple[0]) print(my_tuple[4])
h |
o |
So we had got the output of the given tuple. Therefore that's it for this tuple section.
Article Contributed By :
|
|
|
|
63 Views |