+ 1
It tells robot takes no argument in below code can anybody tell me what's wrong in the code?
class Robot: def _init_ (self, name, color, weight): self.name = name self.color = color self.weight = weight def introduce_self(self): print("My name is " + self.name) r1 = Robot("Tom", "red", 40) r2 = Robot("Jerry", "blue", 30) r1.introduce_self() r2.introduce_self()
5 Respostas
0
The error is that Robot() takes no argument, but why?
It is because the constructor function is a special method. In Python, special methods are written with two underscores before and after.
It is __init__ not _init_
Check it in the code play ground.
0
Check the code again _init_ is already written.
0
Ashish Singh Check my comment again, it is __init__ not _init_
0
Again same error
0
It works in here
The only modification made is the one mentioned above: "__init__"
https://code.sololearn.com/cd060nE1urUc/?ref=app