Program to execute a string containing Python code

In this python function program, we will execute a string containing Python code.

String: A string is any series of characters that are interpreted literally by a script. For example, “Python”.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

 

Steps to solve the program
				
					mycode = 'print("Python")'
code = """
def mutiply(x,y):
    return x*y

print('sqatools')
"""
exec(mycode)
exec(code)
				
			

Output :

				
					Python
sqatools
				
			

Related Articles

create and print a list where the values are squares of numbers between 1 to 10.

access a function inside a function.

Leave a Comment