Python Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is output for −

a = ['he', 'she', 'we']

' '.join(a)

A - ['heshewe']

B - 'heshewe'

C - ['he she we']

D - 'he she we'

Answer : B

Explanation

The method join() takes list of string as input and returns string as output. It removes ', ' and add the given string with join to the list.

Q 2 - How can we swap two numbers a = 10, b = 20 in python without using third variable?

A - a = b

b = a

B - a,b = b,a

C - both a & b

D - b = a

a = b

Answer : C

Explanation

To swap two numbers we can use both a & b option. Both a & b are similar statemnts written in different ways.

Q 3 - What is output of following code −

print('hijk'.partition('ab'))

A - ('hijk', 'cd', ' ')

B - ('hijk')

C - ('hijk', ' ', ' ')

D - Name error

Answer : C

Explanation

Since there are no separators in the given string so the output is the same string.

Q 4 - What is output of following code −

s = ''mnopqr ''
i = ''m ''
while i in s:
   print('i', end= '' '')

A - i i i i i i i i..

B - m m m m m ..

C - m n o p q r

D - no output

Answer : A

Q 5 - What is the output of the following code?

def nprint(message, n):
while(n > 0):
   print(message)
n-=1
nprint('z', 5)

A - zzzz

B - zzzzz

C - Syntax Error

D - Infinite Loop

Answer : D

Explanation

Because decrementing condition of n' is not present in the while loop.

Q 6 - What is the output of the following code?

eval(''1 + 3 * 2'')

A - 1+6'

B - 4*2'

C - 1+3*2'

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

Q 7 - Which of the function among will return 4 on the set s = {3, 4, 1, 2}?

A - Sum(s)

B - Len(s)

C - Max(s)

D - Four(s)

Answer : B & C.

Explanation

len(s) returns the length of the set and max(s) returns the maximum value in the set.

Q 8 - Which method is used to convert raw byte data to a string?

A - Encode()

B - Decode()

C - Convert()

D - tostring()

Answer : B

Explanation

Decode is the method used to convert the raw byte data to a string.

Answer : C

Explanation

Button keyword is used to make a button in Python. To set the process button in command we assign the value processButton in the command. Any text value can be given to the button which is assigned under text keyword.

Q 10 - What is the value of a, b, c in the given below code?

a, b = c = 2 + 2, ''TutorialsPoint''

A - a=4, 'TutorialsPoint'

b= 4, 'TutorialsPoint'

c= 4, 'TutorialsPoint'

B - a=2

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

C - a=4

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

D - a=4

b= 'TutorialsPoint'

c= NULL.

Answer : C

python_questions_answers.htm
Advertisements