0

How does the following python code work?

print(eval("4*5+2")) prints 22 while print(eval("04*5+2")) throws error. I'd really be grateful if someone can explain this to me!

24th Jul 2018, 4:06 AM
Ajai Kannan. K
Ajai Kannan. K - avatar
1 Answer
+ 1
you can not write 0 prefix because python use zero prefix to represent number type. Number SystemPrefix Binary '0b' or '0B' Octal '0o' or '0O' Hexadecimal '0x' or '0X' use like below, print(eval("0x4 * 5 + 2")) print(eval("0b100 * 5 + 2")) print(eval("0o4 * 5 + 2"))
24th Jul 2018, 5:33 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar