0% found this document useful (0 votes)
15 views2 pages

Python Functions, Methods, and Inheritance

The document consists of multiple-choice questions related to Python programming concepts, including methods, variable assignment, inheritance, and the __init__ method. Each question is followed by the correct answer, highlighting key aspects of Python's functionality and object-oriented principles. The content serves as a quiz or review material for understanding Python programming.

Uploaded by

arunm.cloudthat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Python Functions, Methods, and Inheritance

The document consists of multiple-choice questions related to Python programming concepts, including methods, variable assignment, inheritance, and the __init__ method. Each question is followed by the correct answer, highlighting key aspects of Python's functionality and object-oriented principles. The content serves as a quiz or review material for understanding Python programming.

Uploaded by

arunm.cloudthat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

1) In Python, what determines whether a function becomes a method of a class?

A) The presence of the self keyword


B) Declaring it inside a class
C) Using the @classmethod decorator
D) Inheriting from object
Answer: B

2) What happens when you assign a list to another variable like this:
a = [1, 2, 3]
b = a
A) b becomes a copy of a
B) b becomes a reference to a
C) b becomes an immutable version of a
D) An error occurs
Answer: B

3)What will be the output?


x = 10
def func():
print(x)
func()

A) 10
B) Error
C) None
D) 0
Answer: A

4) Which is correct about inheritance in Python?


A) A subclass cannot override parent methods
B) A subclass can only inherit from one parent
C) A subclass can override parent methods
D) Inheritance works only for built-in classes
Answer: C

5) What will be printed:


class A:
value = 5
obj1 = A()
obj2 = A()
[Link] = 10
print([Link], [Link])
A) 5 5
B) 10 10
C) 5 10
D) Error
Answer: B

6) Which statement about __init__ is correct?


A) It returns output from the object
B) It runs automatically when the object is created
C) It is used only in inheritance
D) It must always be written in every class
Answer: B

7) In the following code, what does self.n refer to?


class Test:
def init(self, n):
self.n = n
A) Local variable
B) Global variable
C) Instance attribute
D) Class attribute
Answer: C

8) What concept allows len("hello") and len([1,2,3]) to both work?


A) Overriding
B) Overloading
C) Polymorphism
D) Abstraction
Answer: C

You might also like