eval: Turn a Python String into a Variable or Function

eval: Turn a Python String into a Variable or Function

If you want to turn a string into a function or variable, use eval. In the code above, I turn the string variable_1 to a variable.

eval is especially handy when you don’t want to hardcode the names of your variables or functions.

For example, you can use eval and list comprehension like above to combine all values of different variables into a list.

Link to the source code.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran