Why i am getting AttributeError ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Why i am getting AttributeError ?

class Mobile(): def __init__(self,model): self.model=model def show_model(self): print('Model',self.model) realme=Mobile("hello").show_model() print(realme.model) print(realme.model)

10th Aug 2020, 9:31 AM
3 Answers
+ 3
Because the realme variable refers to a method not an instance of a class. Its just saying take off the ".show_model()" call on line 6 and make it like: realme = Mobile("hello") # then print its model print(realme.model) OR realme.show_model()
10th Aug 2020, 9:50 AM
Slick - avatar
+ 3
Varun show_model() will return None and that's why the value of realme variable will be None
10th Aug 2020, 9:52 AM
AKSHAY🇮🇳 - avatar