Python Online Quiz


Advertisements

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 the output for −

'you are doing well' [2:999]

A - 'you are doing well'

B - ' '

C - Index error.

D - 'u are doing well'

Answer : D

Explanation

Slicing will never give us an error even if we give it too large of an index for the string. It will just return the widest matching slice it can.

Q 2 - Name the python module which supports regular expressions.

A - regex

B - re

C - pyre

D - pyregex

Answer : B

Explanation

re is the module which supports regular expressions and is part of standard library.

We can import re module as − import re.

Q 3 - Syntax error in python is detected by _________at _______

A - compiler/ compile time

B - interpreter/ run time

C - compiler/ run time

D - interpreter/ compile time

Answer : B

Explanation

Syntax error in python is detected by interpreter at run time.

Q 4 - What is output for −

2 * 2 **3

A - 12

B - 64

C - 16

D - 36

Answer : C

Explanation

2**3 gives 2*2*2 i.e. 8, then 2*8 gives 16, since order of precedence is ** then*. ** implies ‘‘ raise to power’’.

Q 5 - What is output of following −

print(''abbzxyzxzxabb''.count(‘abb’,-10,-1))

A - 2

B - 0

C - 1

D - Error

Answer : B

Explanation

It Counts the number of times the substring ‘abb’ is present starting from position 2 and ending at position 11 in the given string.

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

s = ''\t\t\t\n\nTutorialsPoint\n\n\n\t\t\t''
s.strip()

A - '\n\nTutorialsPoint\n\n\n'

B - '\t\t\tTutorialsPoint\t\t\t'

C - 'TutorialsPoint'

D - 'TutorialsPoint' , '\t\t\t\n\n \n\n\n\t\t\t'

Answer : C

Explanation

Strip method is used to remove all the newline and tab spaces code in the string.

Q 7 - Analyze the code −

print(''Recursive Function'') 
def factorial(n): 
   return(n*factorial(n-1))  
factorial(4)

A - Recursive Function 24.

B - Recursive Function.

C - Function runs infinitely and causes a StackOverflowError.

D - Syntax Error.

Answer : C

Explanation

there is no condition in the code to stop the function.

Q 8 - Which code is used to open a file for binary writing?

A - ''w''

B - ''wb''

C - ''r+''

D - ''a''

Answer : B

Explanation

‘b’ format is used to work on the binary format of file.

Answer : C

Q 10 - How you can lift the pen of in turtle?

A - Turtle.lift()

B - Turtle.liftup()

C - Turtle.penup()

D - Turtle.up()

Answer : C

python_questions_answers.htm
Advertisements