tuples code example
Example 1: what are tuples used for
Tuples in Python
An immutable data value that contains related elements.
Tuples are used to group together related data,
such as a person’s name, their age, and their gender.
A tuple is the same as a list except uses parenthisies instead of square brackets.
A tuple is also immutable (cant be changed) unlike a list.
Example:
tup1 = ('physics', 'chemistry', 1997, 2000);
Example 2: what is a tuple in python
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = "a", "b", "c", "d";
tup1[0]
Example 3: changing tuple values
x = ("apple", "banana", "cherry")
y = list(x)
y[1] = "kiwi"
x = tuple(y)
print(x)
Example 4: how to use tupels python
tupel = ('banana',10,True)
print(tupel[2])
Example 5: tuples
tup1 = (12, 34.56);
tup2 = ('abc', 'xyz');
tup3 = tup1 + tup2;
print tup3;
Example 6: tuple in python
tup = ('a','b','c')