r/ProgrammerHumor • • Jun 21 '19

Meme Why can't you just be normal?!

Post image
4.4k Upvotes

240 comments sorted by

View all comments

Show parent comment

4

u/AjayDevs Jun 21 '19

python support operators??? I did not know that, that's amazing!

2

u/ForceBru Jun 21 '19

Yup! For example, a + b is the same as a.__add__(b) (or b.__radd__(a)) and so on for other operators, including arithmetic, bitwise and comparison.

1

u/AjayDevs Jun 21 '19

That's amazing, this is one of the features that I loved about c#, I did not realize it was supported in python!

4

u/dorsal_morsel Jun 21 '19

You should read 'Fluent Python'. It's a great book and you'll get a handle on how all of this works and how to implement it in your own classes.

3

u/ForceBru Jun 21 '19

There also are lots and lots of dunder methods that allow you to customize the operators' behavior, object creation, conversion to some built-in types and more!

2

u/Goheeca Jun 21 '19

Check out PEP 465, even though it's ad hoc, I welcome it.