python - What does this code mean with stripping leading zeroes? -


eval("".join(token.lstrip('0') token in s.split())) 

where s '02 + 00030 - 76'.

all know strips zeroes in front of 02 , 00030 can evaluate 2+30-76. however, don't understand how this. explain combination of functions me?
much.

for token in s.split() 

s.split() evaluates ['02', '+', '00030', '-', '76']

then token.strip('0') converts list - ['2', '+', '30', '-', '76'] removing leading 0s each token.

finally "".join([..]) joins them '2+30-76'.

eval evaluates expression integer.

ps: bad idea use eval on unsanitized user input text. imagine happen if user enters malicious code input.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -