Wednesday, June 17, 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
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS