Tuples Output&error Q&a
Tuples Output&error Q&a
Tuples Output&error Q&a
(a)
plane = ("Passengers", "Luggage")
plane[1] = "Snakes"
(b)
t2 = ('a')
type(t2)
Ans. <class 'str'>
(c)
t3 = ('a',)
type(t3)
Ans. <class 'tuple'>
Prepared and compiled by Lipi Gupta
(d)
T4 = (17)
type(T4)
Ans. <class 'int'>
(e)
T5 = (17,)
type(T5)
Ans. <class 'tuple'>
(f)
tuple = ('a', 'b', 'c', 'd', 'e')
tuple = ('A',) + tuple [1:]
print (tuple)
Ans. ('A', 'b', 'c', 'd', 'e')
(g)
t2 = (4, 5, 6)
t3 = (6, 7)
t4 = t3 + t2
t5 = t2 + t3
Prepared and compiled by Lipi Gupta
print(t4)
print(t5)
Ans.
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
(h)
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
print(t4)
print(t5)
Ans.
(6, 7, 6, 7, 6, 7)
(6, 7, 6, 7, 6, 7)
(i)
t1 = (3, 4)
Prepared and compiled by Lipi Gupta
t2 = ('3', '4')
print(t1 + t2)
Ans. (3, 4, '3', '4')
(80, 88)
()
(88, 85, 80, 88, 83, 86)
(a)
T[1][0: : 2]
Ans. ('are', 'few')
(b)
"a" in T [1] [ 0 ]
Ans.True
(c)
T [ : 1 ] + T[ 1 ]
Ans. ('These', 'are', 'a', 'few', 'words')
Prepared and compiled by Lipi Gupta
(d)
T[ 2 : : 2 ]
Ans. ('that', 'will')
(e)
T[2][2] in T[1]
Ans. True
(a)
t = ('a', 'b', 'c', 'd', 'e')
print(t[5])
Ans. IndexError: tuple index out of range
(b)
t = ('a', 'b', 'c', 'd', 'e')
t[0] = 'A'
Prepared and compiled by Lipi Gupta
(c)
t1 = (3)
t2 = (4, 5, 6)
t3 = t1 + t2
print(t3)
Ans. TypeError: unsupported operand
type(s) for +: 'int' and 'tuple'
(d)
t2 = (4, 5, 6)
t3 = (6, 7)
print(t3 - t2)
Ans. TypeError: unsupported operand
type(s) for -: 'tuple' and 'tuple'
(e)
Prepared and compiled by Lipi Gupta
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
t6 = t3 * (3,)
print(t4)
print(t5)
print(16)
Ans. t6 = t3 * (3,)
TypeError: can't multiply sequence by
non-int of type 'tuple'
(f)
t = ('a', 'b', 'c', 'd', 'e')
1, 2, 3, 4, 5, = t
Ans. SyntaxError: can't assign to literal
(g)
t = ('a', 'b', 'c, d', 'e')
1n, 2n, 3n, 4n, 5n = t
Ans. SyntaxError: invalid syntax
Prepared and compiled by Lipi Gupta
tup1 = ('Mega') * 3
print(len(tup1))