MCQ

Python MCQ and Answers – Part 8

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

1. If a class is derived from two different classes, this is called ______?

A Multilevel inheritance

B Multiple inheritance

C Hierarchical inheritance

D Python inheritance

B
Let’s take an example of multiple inheritance: Here, class C inherits class A and B.

class A:
    pass

class B:
    pass

class C (A, B):
    pass
 

2. What is the output of the following code?
x = True
y = False
z = False
  
if x or y and z: 
    print "STACKHOWTO"
else: 
    print "stackhowto"

A STACKHOWTO

B stackhowto

C The code does not display anything

D None of the above

A
(True or False) evaluates to True.
 

3. What is the output of this expression, 3*1**3?

A 1

B 3

C 9

D 27

B
First it starts with 1 ** 3 because exponentials have a higher priority than multiplication, so 1 ** 3 = 1 and 3 * 1 = 3. The final answer is 3.
 

4. Is Python case sensitive?

A Yes

B No

C Depends on System

D None of the above

A
Let’s take an example :

str1 = 'Car'
str2 = 'car'

if str1 != str2:
    print('str1 and str2 are not equal')

Output:

str1 and str2 are not equal
 

5. What is the output of the following code?
x = True
y = False
z = False
  
if not x or y: 
    print 10
elif not x or not y and z: 
    print 20
elif not x or y or not y and z: 
    print 30
else: 
    print 40

A 10

B 20

C 30

D 40

D
In Python, the order of priority is first NOT, then AND and finally OR.
 

6. Which of the following statements is true?

A In Python, the same operator can behave differently depending on the operands.

B You can change the behavior of operators in Python.

C The special __add__() method is called when the + operator is used.

D All the answers are true

D
 

7. Which of the following statements is invalid?

A _x = 1

B __x = 1

C __str__ = 1

D All the answers are true

D
All instructions will be executed successfully.
 

8. What is the output of the following code?
count = 1 
  
def calculate(): 
    global count 
    for i in (1, 2, 3, 4):  
        count += 1
  
calculate() 
print count

A 1

B 4

C 5

D None of the above

C
 

9. Which of the following instructions will work without error?

A round(2.5)

B round(999.214,3,0)

C round()

D round(102.4879,1,7)

A
Run help(round) in the shell to get details of the parameters passed to the “round” function.
 

10. If the “return” instruction is not used in a function, this one will return:

A 0

B “None” object

C Random value

D Error

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 *