Runtime evaluation: Difference between revisions

(Add header for GW-BASIC)
Line 439:
 
=={{header|Python}}==
{{works with|Python|2.x}}
The [http://docs.python.org/reference/simple_stmts.html#exec exec statement] allows the optional passing in of global and local names via mappings (See the link for full syntax). The example below shows exec being used to parse and execute a string containing two statements:
 
Line 445 ⟶ 446:
print x
'''
10</lang>
 
{{works with|Python|3.x}}
Note that in Python 3.x [http://docs.python.org/py3k/library/functions.html#exec exec] is a function:
 
<lang python>>>> exec('''
x = sum([1,2,3,4])
print(x)
''')
10</lang>
 
Anonymous user