Q:

Python 3.x Beginner: TypeError: dog() takes no arguments

class animal(object):
    def __init__(self,name):
        self.name = name

    def eat(self,food):
        print("{} is eating".format(self.name,food))

class dog():

    def fetch(self,thing):
        print("{} get the {}".format(self.name,thing))

s = dog('r')

error:  Traceback (most recent call last):   File
  "C:\EclipseWorkspaces\csse120\LearnPython\inheritance.py", line 14, in
  
          s = dog('r') TypeError: dog() takes no arguments
Cant figure out whats wrong, please help.

A:

As your error indicates you are trying to create a object of Dog class by passing 'r' parameter to Dog class constructor function. But Dog class does not have a constructor function which accept a char or a string literal as a parameter. It seems like you are trying to use Animal class constructor to create Dog object (Dogs are a subclass of Animal class)
class animal(object):
  def __init__(self,name):
      self.name = name

To solve this error you should first subclass the Dog class and then create a Dog object.
To subclass Animal class,
class dog(animal):
  def fetch(self,thing):
      print("{} get the {}".format(self.name,thing))

Now you can use the Animal class constructor and create Dog objects using s = dog('r') statement.
Tip :- I think it is good to use CapWords convention from the beginning for class names as described in the PEP8 styling conventions.

