Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Class takes no arguments

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): = name
        self.age = age

    def sit(self):
        print( + ' is now sitting.')

    def roll_over(self):
        print( + ' is now rolling over.')

my_dog = Dog('Willie', 6)
print("my dog's name is " + + ".")
print('my dog is ' + str(my_dog.age) + '.')
here is the error message:
Traceback (most recent call last): File "C:/Users/maxya/PycharmProjects/", line 28, in <module> my_dog = Dog('Willie', 6) TypeError: Dog() takes no arguments
Thank you for your help.
scidam wrote Jul-09-2019, 03:06 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
The dunder init method is double underscore on each side __init__
Ok thank you so much!
(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.


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  add() takes 2 positional arguments but 3 were given Man_from_India 3 152 Feb-10-2020, 05:08 PM
Last Post: Man_from_India
  This constructor takes no arguments Friend 2 1,054 Jun-26-2019, 02:54 PM
Last Post: Friend
  takes 21 positional arguments but 24 were given sophsoph 5 803 Jun-21-2019, 12:53 AM
Last Post: ichabod801
  Why Person() takes no arguments dianefly 3 15,489 Oct-22-2018, 04:15 PM
Last Post: dianefly
  Giving class multiple arguments AndyArsalan 1 735 Oct-04-2018, 11:25 PM
Last Post: ODIS
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 1,537 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

Users browsing this thread: 1 Guest(s)