Python executes the string expression function (eval exec execfile), evalexecfile

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.