Wednesday, February 4, 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
32478 POSTS0 COMMENTS
Milvus
125 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11980 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6936 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS