directory

  • The difference between Python eval and exec functions
  • Two. The value of 1 billion intelligent robot core code
  • Guess you like it

Recommended courses for learning Basic Python: Python Learning Directory >> Getting Started with Python

The difference between Python eval and exec functions

Eval and exec are both built-in Python functions that execute Python code. What’s the difference?

  • 1. The eval function can only evaluate the value of a single expression, while the exec function can run code segments dynamically.
  • 2. The exec function directly executes Python code in a file. The eval function does not.
  • 3. The eval function can have a return value, while the exec function always returns None.

Two. The value of 1 billion intelligent robot core code

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file: The difference between Python eval and exec function. Py @time :2021/04/29 08:00 @motto: The program life needs to be accumulated with perseverance. """ while True: ''' replace("?" , "!" Will string Chinese and English state under the question mark? Replace it with an exclamation point! Replace ("?" , "!" ) will string in the Chinese state of the question mark? Replace it with an exclamation point! Replace ("? ", "") string in Chinese"? "replaced by" "" 'print (input (" "). The replace ("?" , "!" ). The replace ("?" , "!" ).replace(",")) Output result: Are you there? In! Hello hello is this a Python tutorial? Python tutorial! Can you learn how to program after watching the tutorial? Learn how to program after watching this tutorial! Can Python have children? Can Python have children?Copy the code

For information about dynamic execution of complex code snippets and Python code in TXT files, see the Python execfile/exec function

3.Guess you like

  1. The Python for loop
  2. The Python string
  3. The Python list
  4. The Python tuple tuple
  5. Python dictionary dict
  6. Python conditional derivations
  7. Python list derivations
  8. Python dictionary derivations
  9. Python function declarations and calls
  10. Python variable argument *argc/**kargcs
  11. Python anonymous function lambda
  12. Python return logic determines expressions
  13. Python string/list/tuple/dictionary conversions
  14. Python local and global variables
  15. The Python type function is different from the isinstance function
  16. Python is differs from ==
  17. Python mutable and immutable data types
  18. Shallow and deep copies of Python

The difference between Python eval and exec

This article is published by the blog – Ape Say Programming Ape Say programming!