...

/

Puzzle 30: Explanation

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:

  1. Expressions are things that have a value (like5 / 7, or 1 < 3).
...