class 11 tuples
class 11 tuples
1. If a = (5, 4, 3, 2, 1, 0) . Find
(a) a[0] (b) a[1] (c) a[a[0]] (d) a[a[-1]]
2.
tuple6 = (1,2,3,4,5)
tuple6 = tuple6 + (6,)
print(tuple6)
3.
t1 = ('Red','Green','Blue')
print(t1*3)
5.
tuple1 = (10,20,30,40,50,60,70,80)
(a) tuple1[2:7]
(b) tuple1[0:len(tuple1)]
(c) tuple1[:5]
(d) tuple1[2:]
(e) tuple1[0:len(tuple1):2]
(f) tuple1[-6:-4]
(g) tuple1[::-1]
6.
tuple1 = (10,20,30,10,40,10,50)
(a) print(tuple1.count(10))
(b) print(tuple1.count(70))
(c) print(tuple1.count(10,2))
(d) print(tuple1.index(30))
(e) print(tuple1.index(70))
7.
tuple1 = (19,12,56,18,9,87,34)
(a) print(sorted(tuple1))
(b) print(min(tuple1))
(c) print(min(tuple1))
(d) print(min(tuple1))
8.
num3,num4) = (10+5,20+5)
print(num3)
print(num4)
9.
t1 = (1, 'python', (2, 3), ('a', 'b'))
print(t1[-1])
10.
Which of the following statements will create a tuple:
1.tp1=("a", "b")
2.tp1[2]=("a", "b")
3.tp1=(3)*3
4.None of these
13.
tp = (5,)
tp1 = tp * 2
print(len(tp1))
14.
Given tp = (5,3,1,9,0). Which of the following two statements will give
the same output?
(i) print( tp[:-1] )
(ii) print( tp[0:5] )
(iii) print( tp[0:4] )
(iv) print( tp[-4:] )
15.
t = (10, 20, 30, 40, 50, 50, 70)
print(t[5:-1])
16.
t = (10, 20, 30, 40, 50, 60, 70)
print(t[5:-1])
17.
If a = (1, 2, 3)
18.
t1 = ("a",)
print(type(t1))
t = ("a")
print(type(t))
19.
a) Is T1 & T2 the same, if not justify
T1 = 3, 4, 5
T2 = ( 3, 4 , 5)
20.
t2 = (4, 5, 6)
t3 = (6, 7)
t4 = t3 + t2
t5 = t2 + t3
print(t4)
print(t5)
21.
t1 = (88,85,80,88,83,86)
a = t1[2:2]
b = t1[2:]
c = t1[:2]
d = t1[:-2]
e = t1[-2:]
f = t1[2:-2]
g = t1[-2:2]
h = t1[:]
22.
T= ("These", ["are" , "a", "few", "words"] , "that", "we", "will" , "use") Find
(a) T[1][0: :2]
(b) "a" in T[1][0]
(c) T[:1] + [1]
(d) T[2::2]
(e) T[2][2] in T[1]
23.
a)
tup1 = ('Python') * 3
print(len(tup1))
b)
tup1 = ('Python',) * 3
print(len(tup1))
24.
Find
a)
x = (1, (2, (3, (4,))))
print(len(x))
print( x[1][0] )
print( 2 in x )
b)
y = (1, (2, (3,), 4), 5)
print( len(y) )
print( len(y[1]))
print( y[2] + 50 )
c)
z = (2, (1, (2, ), 1), 1)
print(z[z[z[0]]])
25.
When would you prefer tuples over lists ?
Tuples are preferred over lists in the following cases:
2.When we want faster access to data that will not change as tuples are
faster than lists.
3.When we want to use the data as a key in a dictionary. Tuples can be used
as keys in a dictionary, but lists cannot.
4.When we want to use the data as an element of a set. Tuples can be used
as elements of a set, but lists cannot.