MCQ

Python MCQ and Answers – Part 7

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

1. What is the output of the following code?
class Library:
  def practice(self, language='Java'):
    print(language)
  
l = Library()
l.practice('Python')

A Python

B Java

C language

D Python Java

A
 

2. What is the data type of the object below?
X = [0, 2, ‘str’, 1]

A Tuple

B Dictionary

C List

D Array

C
[] define a list
 

3. What does the __init__() function do in Python?

A Initializes the class for use.

B This function is called when a new object is instantiated.

C Initializes all data attributes to zero when called.

D None of the above

B
 

4. Which of the following functions converts a “string” to a “float”?

A int(x [,base])

B float(x)

C str(x)

D long(x [,base])

B
float(x) – Convert x to floating point number.
 

5. What is the output of the following code?
class Point:
    def __init__(self, x = 0, y = 0):
      self.x = x+1
      self.y = y+1
      
p1 = Point()
print(p1.x, p1.y)

A (x, y)

B (0, 0)

C (1, 1)

D (None, None)

C
 

6. What is the output of the following code?
a = lambda q: q * 2
b = lambda q: q * 3
x = 2
x = a(x) 
x = b(x) 
x = a(x) 
print x

A 2

B 6

C 24

D Erreur

C
 

7. Which of the following codes uses inheritance?

A

class MyClass:
   Pass

B

class MyClass1(object):
   pass
class MyClass2(object):
   pass

C

class MyClass1:
    pass
class MyClass2(MyClass1):
    pass

D None of the above

C
 

8. Which of the following statements is true?

A Functions are used to create objects in Python.

B Functions make your program faster.

C A function is a piece of code that performs a specific task.

D All the answers are true

C
 

9. What is the output of the following code?
def displayMsg(text):
  print(text, 'is the best platform to learn anything.')

displayMsg('StackHowTo')

A StackHowTo

B is the best platform to learn anything.

C StackHowTo is the best platform to learn anything.

D None of the above

C
 

10. What is the output of the following code?
x = 2.5
y = 2
print x//y

A 1

B 1.0

C 1.5

D Error

B
This type of division is called a “truncated division” where the remainder is truncated or removed.
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 *