wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python MCQs

Total questions: 20

Worksheet time: 10hrs 0mins

Name
Class
Date
1.

What is the maximum length of a Python identifier?

a)

32

b)

16

c)

28

d)

No fixed length is specified

2.

What will be the output of the following code snippet?

print(2**3 + (5 + 6)**(1 + 1))

a)

129

b)

8

c)

121

d)

None of the above

3.

What will be the output of the following code snippet?

a = [1, 2] print(a * 3)

a)

[1, 2]

b)

[1, 2, 1, 2]

c)

Error

d)

[1, 2, 1, 2, 1, 2]

4.

Which of the following is the proper syntax to check if a particular element is present in a list?

a)

if ele in list

b)

if not ele not in list

c)

Both A and B

d)

None of the above

5.

What will be the output of the following code snippet?

numbers = (4, 7, 19, 2, 89, 45, 72, 22) sorted_numbers = sorted(numbers) odd_numbers = [x for x in sorted_numbers if x % 2 != 0] print(odd_numbers)


a)

[7, 19, 45, 89]

b)

[2, 4, 22, 72]

c)

[4, 7, 19, 2, 89, 45, 72, 22]

d)

[2, 4, 7, 19, 22, 45, 72, 89]

6.


Which of the following functions converts date to corresponding time in Python?

a)

strptime()

b)

strftime()

c)

Both A and B

d)

None of the above

7.

What will be the output of the following code snippet?

square = lambda x: x ** 2 a = [] for i in range(5): a.append(square(i)) print(a)

a)

[0, 1, 4, 9, 16]

b)

[1, 4, 9, 16, 25]

c)

[1, 2, 3, 4, 5]

d)

[0, 1, 2, 3, 4]

8.

What will be the output of the following code snippet?

def tester(*argv): for arg in argv: print(arg, end = ' ') tester('Sunday', 'Monday', 'Tuesday', 'Wednesday')

a)

Sunday

b)

Wednesday

c)

Sunday Monday Tuesday Wednesday

d)

None of the above

9.

As what datatype are the *args stored, when passed into a function?

a)

List

b)

Tuple

c)

Dictionary

d)

None of the above

10.

Which of the following blocks will always be executed whether an exception is encountered or not in a program?

a)

try

b)

except

c)

finally

d)

None of these

11.

What keyword is used in Python to raise exceptions?

a)

raise

b)

try

c)

goto

d)

except

12.


What will be the output of the following code snippet?

s1 = {1, 2, 3, 4, 5} s2 = {2, 4, 6} print(s1 ^ s2)

a)

{1, 2, 3, 4, 5}

b)

{1, 3, 5, 6}

c)

{2, 4}

d)

None of the above

13.

What will be the output of the following code snippet?

a = [[], "abc", [0], 1, 0] print(list(filter(bool, a)))

a)

['abc',[0][1]

b)

[1]

c)

["abc"]

d)

None of the above

14.

What will be the output of the following code snippet?

count = 0 while(True): if count % 3 == 0: print(count, end = " ") if(count > 15): break; count += 1

a)

0 1 2 .....15

b)

Infiniote Loop

c)

0 3 6 9 12 15

d)

0 3 6 9 12

15.

What will be the output of the following Python code?

x = [[0], [1]] print((' '.join(list(map(str, x))),))

a)

01

b)

[0] [1]

c)

(’01’)

d)

(‘[0] [1]’,)

16.

What is output of print(math.pow(3, 2))?

a)

9.0

b)

None

c)

9

d)

None of the mentioned

17.

What will be the output of the following Python expression?

print(round(4.576))

a)

4

b)

4.6

c)

5

d)

4.5

18.

What will be the output of the following Python program?

def addItem(listParam): listParam += [1]   mylist = [1, 2, 3, 4] addItem(mylist) print(len(mylist))

a)

5

b)

8

c)

2

d)

1

19.

What are the two main types of functions in Python?

a)

System function

b)

Custom function

c)

Built-in function & User defined function

d)

User function

20.

To add a new element to a list we use which Python command?

a)

list1.addEnd(5)

b)

list1.addLast(5)

c)

list1.append(5)

d)

list1.add(5)