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:
在吗?
在!
你好
你好
是python教程吗?
是python教程!
看完教程就能学会编程吗?
看完教程就能学会编程!
python能生孩子吗
python能生孩子
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
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
Ape say python
No. sweep the micro-channel public concern