InteractiveInterpreter runcode() in Python Last Updated : 26 Mar, 2020 Comments Improve Suggest changes Like Article Like Report With the help of InteractiveInterpreter.runcode() method, we can only execute the pre-compiled source code having single or multiple lines by using InteractiveInterpreter.runcode() method. Syntax : InteractiveInterpreter.runcode(code) Return : Return the result of executed source else error. Example #1 : In this example we can see that by using InteractiveInterpreter.runcode() method, we are able to execute the piece of code and if run is successful we can get the result else error by using this method. Python3 1=1 # import code and InteractiveInterpreter import code from code import InteractiveInterpreter source = 'print("GeeksForGeeks")' compile_code = code.compile_command(source) # Using InteractiveInterpreter.runcode() method InteractiveInterpreter().runcode(compile_code) Output : GeeksForGeeks Example #2 : Python3 1=1 import code from code import InteractiveInterpreter source = 'a = 5; b = 5; li = [a * b for i in range(5)]; print(li)' compile_code = code.compile_command(source) # Using InteractiveInterpreter.runcode() method InteractiveInterpreter().runcode(compile_code) Output : [25, 25, 25, 25, 25] Comment More infoAdvertise with us Next Article Company Preparation J jitender_1998 Follow Improve Article Tags : Python Python code-module Practice Tags : python Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like