Multiple choice quiz about Python - Part 2

To help readers add to their interesting knowledge of Python objects and classes, below the Network Administrator will send you multiple choice questions on this topic. Please try.

  1. Question 1: Which assertion is correct when talking about the following code:
     def printHello(): 
    print("Hello")
    a = printHello()
    1. printHello () is a function and a is a variable. Both are not objects.
    2. Both printHello () and a represent the same object.
    3. printHello () and a are two different objects.
    4. Syntax error. Cannot assign functions to a variable in Python.
  2. Question 2: What is the output of the program below?
     def outerFunction(): 
    global a
    a = 20
    def innerFunction():
        global a
        a = 30
    print('a =', a)
    a = 10
    outerFunction()
    print('a =', a)
    1. a = 10 a = 30
    2. a = 10
    3. a = 20
    4. a = 30
  3. Question 3: Which of the following statements is true?
    1. Class (class) is a detailed plan for the object.
    2. Only one object can be created from a given class.
    3. Both answers are correct.
    4. There is no exact answer.
  4. Question 4: What is the result of the code below?
     class Foo: 
    def printLine(self, line='Python'):
    print(line)
     o1 = Foo() 
    o1.printLine('Java')
    1. Python
    2. line
    3. Java
    4. Java
      Python
  5. Question 5: What is the meaning of __init __ () function in Python?
    1. Create a class to use.
    2. Called when a new object is initialized.
    3. Initialize and bring all data attributes to 0 when called.
    4. There is no right answer.
  6. Question 6: What is the output of the program below?
     class Point: 
    def __init__(self, x = 0, y = 0):
    self.x = x+1
    self.y = y+1
     p1 = Point() 
    print(p1.x, p1.y)
    1. 0 0
    2. 1 1
    3. None None
    4. xy
  7. Question 7: Which of the following code uses Python's inheritance feature?
    1.  class Foo: 
      Pass
    2.  class Foo(object): 
      pass
      class Hoo(object)
      pass
    3.  class Foo: 
      pass
      class Hoo(Foo):
      pass
    4. There is no exact answer.
  8. Question 8: What is a class inherited from two different classes of attributes?
    1. Multi-level inheritance (Multilevel Inheritance)
    2. Multiple Inheritance
    3. Hierarchical Inheritance
    4. Inheritance
  9. Question 9: Which of the following statements is true?
    1. In Python, an operator may have different operations depending on the operand used.
    2. You can change the way operators work in Python.
    3. __add () __ is called when the '+' operator is used.
    4. All answers are correct.
  10. Question 10: The results of the program below are:
     class Point: 
      def __init__(self, x = 0, y = 0): 
    self.x = x
    self.y = y
      def __sub__(self, other): 
    x = self.x + other.x
    y = self.y + other.y
    return Point(x,y)
     p1 = Point(3, 4) 
    p2 = Point(1, 2)
    result = p1-p2
    print(result.x, result.y)
    1. 2 2
    2. forty six
    3. 0 0
    4. 1 1
Update 24 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile