0

How this code works? [Python]

x = 5 print(x << 2) output: 20

20th Apr 2018, 6:15 AM
Mahmudul Hasan Fahim
Mahmudul Hasan Fahim - avatar
8 Answers
20th Apr 2018, 6:49 AM
Oma Falk
Oma Falk - avatar
+ 5
That's binary left shift operator(<<) in python which shifts the number to the left by certain number of bits given to it's right, there is also an right shift operator(>>) https://stackoverflow.com/questions/3411749/operator-in-python #check this site for a list of all operators https://www.tutorialspoint.com/python/python_basic_operators.htm #bitwise operations python https://wiki.python.org/moin/BitwiseOperators
20th Apr 2018, 6:29 AM
Lord Krishna
Lord Krishna - avatar
+ 3
📈A Z M Mushfiqur Rahman📈 is kidding. (-; Koushik Naskar and Oma say the same (-:
20th Apr 2018, 7:00 AM
Oma Falk
Oma Falk - avatar
+ 2
It's a series of 5,10,20,40,80,160.....of x = 0,1,2,3,4,5,6,....
20th Apr 2018, 6:44 AM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
0
Thats a binary left shift operator where the left operand value is moved left by digits specified by the right operand 5 in binary 101 Now move left by two place i.e. 10100 = 20
20th Apr 2018, 6:46 AM
Koushik Naskar
Koushik Naskar - avatar
0
I'm confused.😕
20th Apr 2018, 6:49 AM
Mahmudul Hasan Fahim
Mahmudul Hasan Fahim - avatar
0
MH Fahim whats your confusion here?
20th Apr 2018, 7:07 AM
Koushik Naskar
Koushik Naskar - avatar
0
Koushik Naskar Now i understand bro 😊 Thanks for helping.
20th Apr 2018, 7:57 AM
Mahmudul Hasan Fahim
Mahmudul Hasan Fahim - avatar