exec and Eval in Python

Source: Internet
Author: User
EXEC description

EXEC executes python statements stored in a string or file, and can execute more complex Python code than eval,exec.

return value

The exec return value is always None.

It should be explained that exec is not a function in Python2, but a built-in statement (statement), but there is a execfile () function in Python 2.

It can be understood that Python 3 consolidates the functionality of the EXEC statement and execfile () functions into a new EXEC () function.

Eval description

The eval () function is used to execute a string expression and return the value of the expression

return value

Returns the result of an expression evaluation.

exec and eval similarities and differences

1.Exec can handle the code inside the string (the expression + code that conforms to the Python syntax), and eval can only handle expressions inside the string.

2.exec no return value; eval () is the execution of an expression with a return value, such as a=eval (' + + ').

Both 3.exec and Eval can execute functions in strings such as: Exec (func (n)), eval (func (n)).

exec and Eval in Python

Related Article

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.