Monday, November 18, 2024
Google search engine
HomeLanguagesInteractiveConsole runcode() in Python

InteractiveConsole runcode() in Python

With the help of InteractiveConsole.runcode() method, we can get the output of the single or multiple lines of code, if we want to see the result of some part of code then we can use InteractiveConsole.runcode() method.

Syntax : InteractiveConsole.runcode(code)

Return : Return the output of the code section.

Example #1 :
In this example we can see that by using InteractiveConsole.runcode() method, we are able to get the result of some part of code without running the whole code by using this method.




# import code
from code import InteractiveConsole
  
code = 'print("GeeksForGeeks")'
# Using InteractiveConsole.runcode() method
InteractiveConsole().runcode(code)


Output :

GeeksForGeeks

Example #2 :




# import code
from code import InteractiveConsole
  
code = 'a = 10; print(a + 20)'
# Using InteractiveConsole.runcode() method
InteractiveConsole().runcode(code)


Output :

30

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments