python eval function difference between the exec (36)

   

    eval and exec python are built-in functions, and can execute python code, both specific what difference does it?

 

    1.eval () function can only Calcd single expression, whereas exec () function can run dynamic code segment;

    2.exec () function can be executed directly python code file, eval () function does not achieve this function;

    3.eval () function can return a value, and the exec () function returns the value is always None;

 

    About using eval, worth 10 million intelligent robot core code:

# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author: Why grief
@Blog (personal blog address): shuopython.com
@WeChat Official Account (micro-channel public number): ape says python
@Github:www.github.com
 
@File:python_eval.py
@Time:2019/12/16 21:25
 
@Motto: short step a thousand miles, no small streams converge into a wonderful required the ocean, the program of life relentlessly accumulate!
"""
 
 
while True:
    '''
    replace ( "?", "!") The question mark in a string English state? Replaced with an exclamation point!
    replace ( "?", "!") The question mark in a string Chinese state? Replaced with an exclamation point!
    Replace ( "do", "") of the Chinese character string "do" with ""
    '''
    print(input("").replace("?","!").replace("","!").replace("",""))

 

Test Results:

 

    About exec execute complex dynamic code fragment execution and txt document python code please refer to: python the execfile / exec function

 

 

 

you may also like:

    1.python input / eval function

    2.python dictionary derivations

    3.python list comprehensions

    Creating 4.python thread

 

 

    Reproduced please specify: ape say Python  >>  difference python eval and exec function

 

Technical exchanges, business cooperation please contact bloggers
Scan code or search: ape say python
No public python tutorial
Ape say python
No. sweep the micro-channel public concern

Guess you like

Origin www.cnblogs.com/shuopython/p/12189975.html