Python MCQ
Spread the love

Loading

Q1). What is the output of the following code :

L = [‘a’,’b’,’c’,’d’]

print “”.join(L)

A). Error

B). None

C). abcd

D). [‘a’,’b’,’c’,’d’]

Answer :C

Q2). What is the output of the following program :

y = 8

z = lambda x : x * y

print z(6)

A). 48

B). 14

C). 64

D). None of the above

Answer). A

Q3). What is called when a function is defined inside a class?

A). Module

B Class

C Another Function

D). Method

Answer). D

Q4). Which of the following is the use of id() function in python?

A). Id returns the identity of the object

B). Every object doesn’t have a unique id

C).  All of the mentioned

D).  None of the mentioned

Answer). A

Q 5). Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?

A).  [3, 4, 5, 20, 5, 25, 1, 3]

B). [1, 3, 3, 4, 5, 5, 20, 25]

C). [3, 5, 20, 5, 25, 1, 3]

D). [1, 3, 4, 5, 20, 5, 25]

Answer). C

Q 6). time.time() returns ________

A). the current time

B). the current time in milliseconds

C). the current time in milliseconds since midnight

D). the current time in milliseconds since midnight, January 1, 1970

E). the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)

Answer). E

Q 7). What will be the output of the following code :

print type(type(int))

A). type ‘int’

B). type ‘type’

C). Error

D). 0

Answer). B

Q 8). What will be the output of the following Python code?

l1=[1,2,3]

l2=[4,5,6]

[x*y for x in l1 for y in l2]

a) [4, 8, 12, 5, 10, 15, 6, 12, 18]

b) [4, 10, 18]

c) [4, 5, 6, 8, 10, 12, 12, 15, 18]

d) [18, 12, 6, 15, 10, 5, 12, 8, 4]

Answer). C

Q 9). Write the list comprehension to pick out only negative integers from a given list ‘l’ ?

A).

[x<0 in l]

B). [x for x<0 in l]

C). [x in l for x<0]

D). [x for x in l if x<0]

Answer). D

Q 10). What will be the output of the following Python code?

s=[“pune”, “mumbai”, “delhi”]

[(w.upper(), len(w)) for w in s]

A). Error

B). [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]

C). [PUNE, 4, MUMBAI, 6, DELHI, 5]

D). [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]

Answer). D

Q 11). What will be the output of the following Python code?

import math

[str(round(math.pi)) for i in range (1, 6)]

a) [‘3’, ‘3’, ‘3’, ‘3’, ‘3’, ‘3’]

b) [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’, ‘3.141582’]

c) [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]

d) [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’]

Answer). C

By Hassan Amin

Dr. Syed Hassan Amin has done Ph.D. in Computer Science from Imperial College London, United Kingdom and MS in Computer System Engineering from GIKI, Pakistan. During PhD, he has worked on Image Processing, Computer Vision, and Machine Learning. He has done research and development in many areas including Urdu and local language Optical Character Recognition, Retail Analysis, Affiliate Marketing, Fraud Prediction, 3D reconstruction of face images from 2D images, and Retinal Image analysis in addition to other areas.