Tuple, with example, coding, make game, pygame, python advance, java, python, software, PHP, C programming, Alpha Codist, course, free, python tuple
Tuple
A tuple is a collection of objects ordered and immutable. Tuples are sequences like lists. The differences between tuples and lists are, the tuples cannot be changed. Unlike lists and tuples use parentheses(), whereas lists use square brackets[].
Example:
# You can create tuples in defferent waays
tuple1 = ("Alpha Codist", 2020, "Is the best")
tuple2 = "Alpha", "Codist", "Is the best";
tuple3 = (2020,);
# In this way you can join tuples and you can even multiply tuples
tuple4 = tuple2+tuple3
print(tuple1)
print(tuple2)
print(tuple3)
print(tuple4)
# You can check for items
print(2020 in tuple1)
# you can not edit by using indexing but you can read.
print(tuple1[0])
Result:
Tuple 1:
Tuple 2:
Tuple 3:
Tuple 4:
You can check for elements availability:
You can not edit by using indexing but you can read:
Some of the data were collected. Source: (Tutorialspoint.com)
COMMENTS