Understanding Python’s eval()
You can use the built-in Python eval() to dynamically evaluate expressions from a string-based or compiled-code-based input. If you pass in a string to eval(), then the function parses it, compiles it to bytecode, and evaluates it as a Python expression. But if you call eval() with a compiled code object, then the function performs just the evaluation step, which is quite convenient if you call eval() several times with the same input.
The signature of Python’s eval() is defined as follows:
eval(expression[, globals[, locals]])
The function takes a first argument, called expression, which holds the expression that you need to evaluate. eval() also takes two optional arguments:
globals
locals
In the next three sections, you’ll learn what these arguments are and how eval() uses them to evaluate Python expressions on the fly.
Python eval() Function
Example
Evaluate the expression 'print(55)':
x = 'print(55)'
eval(x)
Definition and Usage
The eval() function evaluates the specified expression, if the expression is a legal Python statement, it will be executed.
Syntax
eval(expression, globals, locals)
Parameter Values
Parameter Description
expression A String, that will be evaluated as Python code
globals Optional. A dictionary containing global parameters
locals Optional. A dictionary containing local parameters
На этой странице сайта вы можете посмотреть видео онлайн @eval()_function длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Nielit Online Academy By Satya Sir 01 Январь 1970, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 33 раз и оно понравилось 3 зрителям. Приятного просмотра!