Basic Python3 Code Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Basic Python3 Code Question

I am a Pyhon3_Bignner. I don't understand this code. Please help me. x = 5 print(x>>2<<x) #answer = 32 print(x>>2) is 1, and print(x<<2) is 20. How does '>>' and '<<' work ?

19th Jun 2020, 10:39 PM
hirofumi yamada
hirofumi yamada - avatar
4 Answers
+ 2
Thank you, Kevin! I understand. Thanks!!
19th Jun 2020, 11:30 PM
hirofumi yamada
hirofumi yamada - avatar
+ 1
hirofumi yamada What do you mean? You never changed x in your program. x = 5 If you want to modifie x use: x >>= 2 And now x is 1
19th Jun 2020, 11:22 PM
Kevin ★
0
Thanks! Now, I know that. x>>2 is 5('000101') to 1('000001'). and 2<<x(=5) is 1('000001') to 32('100000'). So, answer is 32. But, '2<<x' isn't '2<<1' ?
19th Jun 2020, 11:11 PM
hirofumi yamada
hirofumi yamada - avatar