[python] Is it not possible to define multiple constructors in Python?

Possible Duplicate:
What is a clean, pythonic way to have multiple constructors in Python?

Is it not possible to define multiple constructors in Python, with different signatures? If not, what's the general way of getting around it?

For example, let's say you wanted to define a class City.

I'd like to be able to say someCity = City() or someCity = City("Berlin"), where the first just gives a default name value, and the second defines it.

This question is related to python constructor

The answer is


Unlike Java, you cannot define multiple constructors. However, you can define a default value if one is not passed.

def __init__(self, city="Berlin"):
  self.city = city

Similar questions with python tag:

Similar questions with constructor tag: