Returns a runnable code object created from a
compile(source, filename, mode)
source: string or AST object
filename: The file from which the code is being read
eval: It accepts only a single expression.
exec: It can take a code block that has Python statements, class and functions, and so on.
single: It consists of a single interactive statement.
dont_inherit(optional): Controls which future statements affect the compilation of the source. Default set to 0.
optimize(optional): The optimization level of the compiler. Default set to -1.
compile() to take a code block and return a runnable code object.
x = compile('print(55)\nprint(88)', 'test', 'exec')exec(x)
This will output:
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
- Anonymous contributors
Learn Python on Codecademy
- Anonymous contributorsAnonymous contributors