Puzzle 30: Explanation
Let’s find out how to use Python’s built-in eval and exec functions.
We'll cover the following...
Try it yourself
Try executing the code below to verify the results:
Press + to interact
a = eval('a = 7')val = eval('a * 3')print(val)
Explanation
The built-in eval function reads a Python expression as a string and returns its value.
We tend to split the code into two categories:
- Expressions are things that have a value (like
5 / 7
, or1 < 3
).