Thursday, September 4, 2025
HomeLanguagesInteractiveInterpreter runsource() in Python

InteractiveInterpreter runsource() in Python

With the help of InteractiveInterpreter.runsource() method, we can compile and run the source having single or multiple lines by using InteractiveInterpreter.runsource() method.

Syntax : InteractiveInterpreter.runsource(code)

Return : Return the Output if compile successful else false with error.

Example #1 :
In this example we can see that by using InteractiveInterpreter.runsource() method, we are able to compile and run the piece of code and if run is successful we can get the result else false by using this method.




# import code and InteractiveInterpreter
from code import InteractiveInterpreter
  
code = 'print("GeeksForGeeks")'
# Using InteractiveInterpreter.runsource() method
InteractiveInterpreter().runsource(code)


Output :

GeeksForGeeks

Example #2 :




# import code and InteractiveInterpreter
from code import InteractiveInterpreter
  
code = 'a = 8; b = 2.5; -a = a + b'
# Using InteractiveInterpreter.runsource() method
InteractiveInterpreter().runsource(code)


Output :

SyntaxError: can’t assign to operator
False

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

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS