__init__() missing 1 required positional argument ‘address’

Your __init__ is declared as taking a name and an address:

def __init__(self, name, address):

This means that you need to provide both of them, so the following is not valid:

p = Person('Swaroop')

If you have use cases where the address cannot be provided, then you can make the argument optional:

def __init__(self, name, address=None):

The above statement will give address a default value of None if the argument is not provided.


Taking a closer look at your code it seems you wanted to provide a name and an address as two separate objects:

p = Person('Swaroop') # name
q = Person('Duisburg') # address

Note that arguments are identified by position, so on q, Duisburg will correspond to the name argument.

You can achieve what you want by using just one object:

p = Person('Swaroop', 'Duisburg')
p.say_name()
p.say_address()

Leave a Comment