Skip to content

Instantly share code, notes, and snippets.

@ROBOMASTER-S1
Last active March 6, 2023 18:04
Show Gist options
  • Save ROBOMASTER-S1/a8333ba0adccef82e92e2470ba56e85c to your computer and use it in GitHub Desktop.
Save ROBOMASTER-S1/a8333ba0adccef82e92e2470ba56e85c to your computer and use it in GitHub Desktop.
The exec function Python Program Examples: Created by Joseph C. Richardson
# Sometimes if you are going to be using and reusing small bits of Python code
# over and over again, you might want to consider using the 'exec' function.
# The 'exec' function can be used in such examples as these examples below.
# Created by Joseph C. Richardson, GitHub.com
redundant_code='''
print("Python Programmer's Glossary Bible")
print('This block of code can be used and reused again and again.')
'''
'''----------------------------------------------------------------'''
# Call the 'exec' funcion as many times as you please.
exec(redundant_code)
exec(redundant_code)
exec(redundant_code)
'''----------------------------------------------------------------'''
# Here is an example, using a for-loop to call the 'exec' function.
for i in range(3):
exec(redundant_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment