Python executes the string expression function (eval exec execfile), evalexecfile
After careful study, I learned three functions:
Eval: calculates the expression in the string.
Exec: Execute the statement in the string
Execfile: used to execute a file
It should be noted that exec is a statement, while eval () and execfile () are built-in built-in functions.
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> x=1>>> print eval("x+1")2>>> exec "print 'http://blog.leniy.org/python-eval-exec-execfile.html'"http://blog.leniy.org/python-eval-exec-execfile.html>>>
At the same time, we sometimes use input to input some data, such
>>> Input ("Enter:") Enter 1 + 2 ** 39 >>>
In fact, the input here is also an eval application, which is equivalent
>>> Eval (raw_input ("Enter:") Enter 1 + 2 ** 39 >>>
What job is the eval () function in python?
The eval parameter is a string that can be evaluated as an expression,
For example, 'x + 1' is an expression string.
>>> X = 1
>>> Print eval ('x + 1 ')
2
Python built-in functions
I am also learning python. How can I discuss it together?