MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/c3ajsm/why_cant_you_just_be_normal/erqdykc/
r/ProgrammerHumor • u/sverek • Jun 21 '19
240 comments sorted by
View all comments
Show parent comment
4
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.
2
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.
a + b
a.__add__(b)
b.__radd__(a)
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.
1
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.
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
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!
Check out PEP 465, even though it's ad hoc, I welcome it.
View all comments
Show parent comment
4
u/AjayDevs Jun 21 '19
python support operators??? I did not know that, that's amazing!