wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

QUIZ ON STRINGS - TUPLES - SET - DICTIONARY

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What will be the output of the following Python code?

print("Hello {name1} and {name2}".format(name1='Covalence', name2='Global'))

a)

Hello Covalense and Global

b)

Hello {name1} and {name2}

c)

Error

d)

Covalense and Global

2.

What will be the output of the “hello” +1+2+3?

a)

hello123

b)

hello

c)

hello6

d)

Error

3.

What is “Hello”.replace(“l”, “e”)?

a)

Heeeo

b)

Heelo

c)

Heleo

d)

None

4.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy'))

a)

2

b)

0

c)

5

d)

Error

5.

What will be the output of the following Python code?

print("abcdef".find("cd"))

a)

True

b)

2

c)

False

d)

Error

6.

What will be the output of the following Python code?

print('xyyzxxyxyy'.lstrip('xyy'))

a)

zxxyxyy

b)

zxxy

c)

z

d)

Error

7.

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

a)

print(t[3])

b)

t[3] = 45

c)

print(max(t))

d)

print(len(t))

8.

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:-1]

a)

(1, 2)

b)

(1, 2, 4)

c)

(2, 4)

d)

(2, 4, 3)

9.

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

a)

1

b)

2

c)

5

d)

Error

10.

What type of data is: a=[(1,1),(2,4),(3,9)]?

a)

Array of tuples

b)

List of tuples

c)

Tuples of lists

d)

Invalid type

11.

What will be the output of the following Python code?

>>> a=(1,2)

>>> b=(3,4)

>>> c=a+b

>>> print(c)

a)

(4,6)

b)

(1,2,3,4)

c)

Error as tuples are immutable

d)

None

12.

What will be the output of the following Python code?

>>>nums = set([1,1,2,3,3,3,4,4])

>>>print(len(nums))

a)

7

b)

4

c)

8

d)

Error, invalid syntax for formation of set

13.

Which of the following statements is used to create an empty set?

a)

{ }

b)

set()

c)

[ ]

d)

( )

14.

If a={5,6,7,8}, which of the following statements is false?

a)

print(len(a))

b)

print(min(a))

c)

a.remove(5)

d)

a[2]=45

15.

What will be the output of the following Python code?

>>> a={4,5,6}

>>> b={2,8,6}

>>> a-b

a)

{4,5}

b)

{6}

c)

Error as unsupported operand type for set data type

d)

Error as the duplicate item 6 is present in both sets

16.

Is the following Python code valid?

>>>a={3,4,{7,5}}

>>>print(a[2][0])

a)

Yes, 7 is printed

b)

Error, elements of a set can’t be printed

c)

Error, subsets aren’t allowed

d)

Yes, {7,5} is printed

17.

What will be the output of the following Python code snippet?

for x in set('pqr'):

print(x*2)

a)

pp

qq

rr

b)

pqr

pqr

c)

ppqqrr

d)

pqrpqr

18.

Which of the following statements create a dictionary?

a)

d = { }

b)

d = {“john”:40, “peter”:45}

c)

d = {40:”john”, 45:”peter”}

d)

All of the mentioned

19.

What will be the output of the following Python code snippet?

>>>d = {"john":40, "peter":45}

>>>d["john"]

a)

40

b)

45

c)

“john”

d)

“peter”

20.

What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}

for i,j in a.items():

print(i,j,end=" ")

a)

1 A 2 B 3 C

b)

1 2 3

c)

A B C

d)

1:”A” 2:”B” 3:”C”

21.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

a.clear()

print(a)

a)

None

b)

{ None:None, None:None, None:None}

c)

{1:None, 2:None, 3:None}

d)

{ }

22.

What will be the output of the following Python code?

a={1:5,2:3,3:4}

a.pop(3)

print(a)

a)

{1: 5}

b)

{1: 5, 2: 3}

c)

Error, syntax error for pop() method

d)

{1: 5, 3: 4}

23.

What will be the output of the following Python code snippet?

>>> a={1:"A",2:"B",3:"C"}

>>> del a

a)

method del doesn’t exist for the dictionary

b)

del deletes the values in the dictionary

c)

del deletes the entire dictionary

d)

del deletes the keys in the dictionary

24.

What will be the output of the following Python code snippet?

test = {1:'A', 2:'B', 3:'C'}

test = {}

print(len(test))

a)

0

b)

3

c)

Error

25.

What will be the output of the following Python code?

>>> a={i: i*i for i in range(6)}

>>> a

a)

Dictionary comprehension doesn’t exist

b)

{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}

c)

{0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}

d)

{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}