+ 1
How can I convert string to keyword?
https://code.sololearn.com/crjHLZDky29i/?ref=app The string doesn't get recognized as the assigned keyword and I can't do string calculations otherwise.
3 Antworten
+ 2
print(eval("bobobo")+eval("bobobo"))
With eval you can interpret strings as expressions.
There's probably a better way. Wanna describe what exactly you're planning to do?
+ 2
Thank you.
I have no plans for this, I'm learning my first language and trying to see in which ways I can or cannot use different functions, so I can find solutions more easily in the future, if need arises.
+ 1
I might add that you can only use eval for strings that have a value.
If you want to parse whole code, you'll need exec instead of eval.
So for example:
exec('while True: print("Hello!")')