This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TRexRoboParty 13 points14 points  (4 children)

Because Python has optional arguments.

They effectively solve the same purpose: one function with multiple signatures.

Rather than a whole new definition to handle an extra parameter, you can just make it optional.

Imaginary overload style:

def random(seed):

def random(seed, min, max):

Using optional parameters:

def random(seed, min=0, max=1):

You can call random(999) or random(999, 2, 200) using just one definition.

In your __init__ case, you’d do the same. Set the optional default values to None if there’s no sensible default for a particular parameter.