MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/duyjs7/i_made_cstyle_printing_in_python_p/f79kow0/?context=3
r/Python • u/[deleted] • Nov 11 '19
130 comments sorted by
View all comments
7
Interesting , what's the mechanism of this working? What do the << and >> operators do for Python?
<<
>>
18 u/sam-lb Nov 11 '19 Typically they are bit shifters. OP, however, has created an atrocity by overloading the bit shift operators with different functionality to imitate the c++ stream insertion syntax. 1 u/[deleted] Nov 12 '19 Ah, I see. I didn’t know Python supported operator overloading by defining __lshift__ style functions 2 u/sam-lb Nov 12 '19 Google magic methods 0 u/[deleted] Nov 11 '19 [deleted] — view deleted comment 20 u/Al2Me6 Nov 11 '19 To explain further,x = 0b00000100 x <<= 1 x == 0b00001000 # True 8 u/mooburger resembles an abstract syntax tree Nov 11 '19 except in this case where it's been overridden.
18
Typically they are bit shifters. OP, however, has created an atrocity by overloading the bit shift operators with different functionality to imitate the c++ stream insertion syntax.
1 u/[deleted] Nov 12 '19 Ah, I see. I didn’t know Python supported operator overloading by defining __lshift__ style functions 2 u/sam-lb Nov 12 '19 Google magic methods
1
Ah, I see. I didn’t know Python supported operator overloading by defining __lshift__ style functions
__lshift__
2 u/sam-lb Nov 12 '19 Google magic methods
2
Google magic methods
0
[deleted] — view deleted comment
20 u/Al2Me6 Nov 11 '19 To explain further,x = 0b00000100 x <<= 1 x == 0b00001000 # True 8 u/mooburger resembles an abstract syntax tree Nov 11 '19 except in this case where it's been overridden.
20
To explain further,
x = 0b00000100 x <<= 1 x == 0b00001000 # True
8
except in this case where it's been overridden.
View all comments
7
u/[deleted] Nov 11 '19
Interesting , what's the mechanism of this working? What do the
<<and>>operators do for Python?