Thursday, February 5, 2026
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
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32487 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6861 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12071 POSTS0 COMMENTS
Shaida Kate Naidoo
6994 POSTS0 COMMENTS
Ted Musemwa
7234 POSTS0 COMMENTS
Thapelo Manthata
6945 POSTS0 COMMENTS
Umr Jansen
6928 POSTS0 COMMENTS