Advertisements
Advertisements
प्रश्न
In the code given what will be output if the following command is given: (Assuming YC is the object) YC.display()
class Yourclass
marks=10
name= "ABC"
def __init__(self,marks,name):
self.marks=marks
self.name=name
def display(self):
print marks
print nameलघु उत्तर
Advertisements
उत्तर
The given display() method uses marks and name without self. Hence, in Python 3 it raises an error because these names are not local or global variables.
NameError: name 'marks' is not defined
Correct method:
def display(self):
print(self.marks)
print(self.name)
After correction, for YC = Yourclass(10, "ABC"), the output will be:
10
ABC
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
