Birju Shah
0
Q:

make a tuple of any object in python

# A tuple is a sequence of immutable Python objects. Tuples are
# sequences, just 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.
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = "a", "b", "c", "d";

# To access values in tuple, use the square brackets for
# slicing along with the index or indices to obtain value
# available at that index.
tup1[0] # Output: 'physics'
24
#A tuple is essentailly a list with limited uses. They are popular when making variables 
#or containers that you don't want changed, or when making temporary variables.
#A tuple is defined with parentheses.
3
# tuple repitition works like this 
print(('Hi!',) * 4) # output: ('Hi!', 'Hi!', 'Hi!', 'Hi!')
0

New to Communities?

Join the community