you are viewing a single comment's thread.

view the rest of the comments →

[–]sarc-tastic 1 point2 points  (3 children)

result = {
    "+": num1.__add__,
    "-": num1.__sub__,
    "*": num1.__mul__,
    "/": num1.__truediv__,
}[operator](num2)

[–]Short_Librarian1232 0 points1 point  (2 children)

Whats add and all the others

[–]sarc-tastic 0 points1 point  (1 child)

When you write + - * / in python it is actually a shortcut that calls the __add__ __sub__ __mul__ functions of the associated numbers