Computer Science
Predict the output.
tuple_a = 'a', 'b'
tuple_b = ('a', 'b')
print (tuple_a == tuple_b)
Python Tuples
12 Likes
Answer
Output
True
Explanation
Tuples can be declared with or without parentheses (parentheses are optional). Here, tuple_a
is declared without parentheses where as tuple_b
is declared with parentheses but both are identical. As both the tuples contain same values so the equality operator ( == ) returns true.
Answered By
9 Likes
Related Questions
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ( 'a', 'b', 'c', 'd', 'e') a, b, c, d, e, f = t
What would be the output of following code if
ntpl = ("Hello", "Nita", "How's", "life?") (a, b, c, d) = ntpl print ("a is:", a) print ("b is:", b) print ("c is:", c) print ("d is:", d) ntpl = (a, b, c, d) print(ntpl[0][0]+ntpl[1][1], ntpl[1])
Find the error. Following code intends to create a tuple with three identical strings. But even after successfully executing following code (No error reported by Python), The len( ) returns a value different from 3. Why ?
tup1 = ('Mega') * 3 print(len(tup1))
Predict the output.
tuple1 = ('Python') * 3 print(type(tuple1))