MCQ

Python MCQ and Answers – Part 5

This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
 

1. Which operator is overloaded by the or() function?

A //

B /

C ||

D |

D
The or() function overrides the binary OR operator.
 

2. To define a code block in Python, we use _____?

A Braces

B Indentation

C Parenthesis

D Double quote

B
 

3. What is the output of the following program?
i = 0
while i < 3:
       print i
       i++
       print i+1

A 0 2 1 3 2 4

B 1 0 2 4 3 5

C 0 1 2 3 4 5

D Error

D
The ++ operator does not exist in Python, To increment we use the following instruction i=i+1
 

4. Which of the following statements is correct?

A The variable name can begin with an underscore “_”.

B The variable name can start with a number.

C Keywords cannot be used as a variable name.

D The variable name can have symbols like: @, #, $ etc.

A
 

5. What is the output of the following program?
print "Welcome to StackHowTo"[::-1]

A oTwoHkcatS ot emocleW

B Welcome to StackHowTo

C o

D Error

A
[:: – 1] returns the reversed string.
 

6. In the following code n = '2', n is a(n) _______?:

A char

B integer

C string

D tupl

C
 

7. Given a function that returns no value, what value is displayed when it is executed on the shell?

A bool

B int

C void

D None

D
Python explicitly returns ‘None’ object if no value is specified.
 

8. What is the output of the following program?
print(1, 2, 3, 4, sep='*')

A 1 2 3 4

B 1*2*3*4

C 1234

D 24

B
 

9. Which Python module supports regular expressions?

A pyregex

B regex

C re

D None of the above

C
“re” is part of the standard library and can be imported with: import re.
 

10. To get user input in Python, we use _______?

A <>

B input()

C scanf()

D cin

B
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *