How to use exec statement to execute a statement

Execute a statement inside a string

We can use exec statement to create code on the fly and execute them.


exec "print 'Hello, world!'" 

The code above generates the following result.





















Home »
  Python »
    Language Basics »




Python Basics
Operator
Statements
Function Definition
Class
Buildin Functions
Buildin Modules