0% found this document useful (0 votes)
26 views4 pages

class 11 tuples

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

class 11 tuples

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Predict the output

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

11.Which of the following is/are correctly declared tuple(s) ?

a = ("Hina", "Mina", "Tina", "Nina")


a = "Hina", "Mina", "Tina", "Nina")
a = ["Hina", "Mina", "Tina", "Nina"]
a = (["Hina", "Mina", "Tina", "Nina"

12. Which of the following will create a single element tuple ?

a.(1,) b.(1) c.( [1] ) d.tuple([1])

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)

(a) what is the difference (if any) between a * 3 and (a, a, a) ?


(b) Is a * 3 equivalent to a + a + a ?
(c) what is the meaning of a[1:1] ?
(d) what is the difference between a[1:2] and a[1:1] ?
(e) print(a[:])

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)

b) Is T1 & T2 the same, if not justify


T3 = (3, 4, 5)
T4 = (( 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:

1.When we want to ensure that data is not changed accidentally. Tuples


being immutable do not allow any changes in its data.

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.

You might also like