Class takes no arguments - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Class takes no arguments (/thread-19656.html) |
Class takes no arguments - Myang123 - Jul-09-2019 Hey, I am writing a basic class and I am having problems inserting arguments into the class "Dog". Here is the source code class Dog(): def _init_(self, name, age): self.name = name self.age = age def sit(self): print(self.name.title() + ' is now sitting.') def roll_over(self): print(self.name.title() + ' is now rolling over.') my_dog = Dog('Willie', 6) print("my dog's name is " + my_dog.name.title() + ".") print('my dog is ' + str(my_dog.age) + '.')here is the error message: Thank you for your help.
RE: Class takes no arguments - metulburr - Jul-09-2019 The dunder init method is double underscore on each side __init__ RE: Class takes no arguments - Myang123 - Jul-10-2019 Ok thank you so much! RE: Class takes no arguments - Davy_Jones_XIV - Nov-26-2019 (Jul-10-2019, 11:18 PM)Myang123 Wrote: Ok thank you so much! Hello Myang123, I saw this same problem and one question I had was already answered, but I had another that I hope you can help with. How did you get the line below to work? my_dog = Dog("Peso") I placed it outside the code block(>>>) and inside the code block(...) and both failed. The return message is(...) invalid syntax and (>>>) Dog is not defined. I am hoping that you are able to point me in the right direction. Thanks! DJXIV |