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.
- Question 1: Which assertion is correct when talking about the following code:
def printHello():
print("Hello")
a = printHello()
- printHello () is a function and a is a variable. Both are not objects.
- Both printHello () and a represent the same object.
- printHello () and a are two different objects.
- Syntax error. Cannot assign functions to a variable in Python.
-
- 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)
- a = 10 a = 30
- a = 10
- a = 20
- a = 30
-
- Question 3: Which of the following statements is true?
- Class (class) is a detailed plan for the object.
- Only one object can be created from a given class.
- Both answers are correct.
- There is no exact answer.
-
- Question 4: What is the result of the code below?
class Foo:
def printLine(self, line='Python'):
print(line)
o1 = Foo()
o1.printLine('Java')
- Python
- line
- Java
- Java
Python
-
- Question 5: What is the meaning of __init __ () function in Python?
- Create a class to use.
- Called when a new object is initialized.
- Initialize and bring all data attributes to 0 when called.
- There is no right answer.
-
- 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)
- 0 0
- 1 1
- None None
- xy
-
- Question 7: Which of the following code uses Python's inheritance feature?
-
class Foo:
Pass
-
class Foo(object):
pass
class Hoo(object)
pass
-
class Foo:
pass
class Hoo(Foo):
pass
- There is no exact answer.
-
- Question 8: What is a class inherited from two different classes of attributes?
- Multi-level inheritance (Multilevel Inheritance)
- Multiple Inheritance
- Hierarchical Inheritance
- Inheritance
-
- Question 9: Which of the following statements is true?
- In Python, an operator may have different operations depending on the operand used.
- You can change the way operators work in Python.
- __add () __ is called when the '+' operator is used.
- All answers are correct.
-
- 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)
- 2 2
- forty six
- 0 0
- 1 1
-
4.2 ★ | 10 Vote
You should read it
- Multiple choice quiz about Python - Part 3
- Multiple choice quiz about Python - Part 4
- Multiple choice quiz about Python - Part 7
- Multiple choice test on Python - Part 11
- Multiple choice quiz about Python - Part 10
- Multiple choice quiz about Python - Part 5
- Multiple choice quiz about Python - Part 1
- Multiple choice quiz about Python - Part 6
- Multiple choice quiz about Python - Part 8
- Multiple choice quiz about Python - Part 9
- More than 100 Python exercises have solutions (sample code)
- How to set up Python to program on WSL