Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
print(int('0010'+'1011')) what will output and explain??
Here 0010 and 1011 are string type when added the output will be 00101011 but it is wrong. can you explain....
4 Answers
+ 6
Output is 101011. This is what Python assumed you wanted, the leading zeroes are ignored because decimal number doesn't care about leading zeroes.
If you want `int()` function to treat the concatenated string as binary number, then call it as follows:
print(int('0010' + '1011', 2))
+ 3
Both the strings will get concatenated. Leading zeros have no meaning so output will be 101011 because u r converting it into int
+ 1
101011, because leading 0s will be removed.
0
Can you tell another example??