About 237,000 results
Open links in new tab
  1. How do I execute a string containing Python code in Python?

    For statements, use exec(string) (Python 3) or exec string (Python 2): >>> my_code = 'print("Hello world")' >>> exec(my_code) Hello world When you need the value of an expression, use …

  2. Execute a String of Code in Python - GeeksforGeeks

    Jan 10, 2025 · Sometimes, we encounter situations where a Python program needs to dynamically execute code stored as a string. We will explore different ways to execute these …

  3. Python's exec(): Execute Dynamically Generated Code

    Python’s built-in exec() function allows you to execute arbitrary Python code from a string or compiled code input. The exec() function can be handy when you need to run dynamically …

  4. Python exec() with Examples - Python Geeks

    Learn Python exec() function, difference between exec() & eval(), and problem with exec(). See different cases of local and global parameters.

  5. How to Use exec() in Python - Everything You Need to Know

    Jul 30, 2023 · The exec() function in Python allows us to execute the block of Python code from a string. This built-in function in Python can come in handy when we need to run the dynamically …

  6. Execute a String Containing Python Code in Python

    In Python, it is possible to execute the dynamically generated code or code stored as a string using the Python built-in functions like eval() and exec(). Both eval() and exec() functions …

  7. How do I execute a string containing Python code in Python?

    Mar 28, 2023 · In this post, we will learn How to execute a String containing Python code in Python which we can perform using exec() which it takes the String containing python code as …

  8. Running a String as Code in Python: A Comprehensive Guide

    Apr 16, 2025 · In this blog post, we will explore the fundamental concepts, usage methods, common practices, and best practices of running a string as code in Python. The eval() …

  9. Python Exercise: Execute a string containing Python code

    Apr 22, 2025 · Write a Python program to execute a string containing Python code. Sample Solution: return x*y. Explanation: In the exercise above the code utilizes the "exec ()" function …

  10. Python Program to execute a String of Code in Python

    Jul 5, 2021 · In this tutorial, we will learn to execute code given in a string format in Python. On executing the Python code which is given inside a string, we should get the result after …

  11. Some results have been removed
Refresh