In languages that use static binding like java you can define multiple functions all having the same name but different parameters. Learning Python, until now I considered the lack of this mainly as "safety issue" (like bool_parameter="False"
might be interpreted as True
because of the quotes). I thought I would simply need to be more careful.
Now I found a situation, where the lack of static binding is simply inconvenient. Please consider this tupel:
var = ((1, "foo"), (2, "bar"), (3, "potato"))
To remove an item from var
with static binding one could do something like this(pseudocode:
def del_item(int i):
# search item with (x == i, *)
# remove this item
def del_item(String s):
# search item with (*, x == s)
# remove this item
I find this very convenient, because no conditions are needed to select the right action to perform. Furthermore this code makes overloading easier, as one can decide to just overload one of the functions or both.
Trying to deal with a situation like this in Python, I only find inconvenient solutions like some if-clauses that check for the type.
Is there a better way?
Python doesn't have overloading of methods so you're going to have to check the type of the argument sorry.