Understanding the Execution of Python Program Last Updated : 10 Jul, 2020 Comments Improve Suggest changes Like Article Like Report This article aims at providing a detailed insight into the execution of the Python program. Let's consider the below example. Example: Python3 a = 10 b = 10 print("Sum ", (a+b)) Output: Sum 20 Suppose the above python program is saved as first.py. Here first is the name and .py is the extension. The execution of the Python program involves 2 Steps: CompilationInterpreterCompilation The program is converted into byte code. Byte code is a fixed set of instructions that represent arithmetic, comparison, memory operations, etc. It can run on any operating system and hardware. The byte code instructions are created in the .pyc file. The .pyc file is not explicitly created as Python handles it internally but it can be viewed with the following command: -m and py_compile represent module and module name respectively. This module is responsible to generate .pyc file. The compiler creates a directory named __pycache__ where it stores the first.cpython-38.pyc file. Interpreter The next step involves converting the byte code (.pyc file) into machine code. This step is necessary as the computer can understand only machine code (binary code). Python Virtual Machine (PVM) first understands the operating system and processor in the computer and then converts it into machine code. Further, these machine code instructions are executed by processor and the results are displayed. Execution of Python Program However, the interpreter inside the PVM translates the program line by line thereby consuming a lot of time. To overcome this, a compiler known as Just In Time (JIT) is added to PVM. JIT compiler improves the execution speed of the Python program. This compiler is not used in all Python environments like CPython which is standard Python software. To execute the first.cpython-38.pyc we can use the following command: To view the byte code of the file - first.py we can type the following command as : The dis command is known as "disassembler" that displays the byte code in an understandable format. The code represents 5 columns: Line Numberoffset position of byte codename of byte code instructioninstruction's argumentconstants or names (in brackets) Comment More infoAdvertise with us Next Article Understanding the Execution of Python Program Y yojanabavkar Follow Improve Article Tags : Python Python Programs python-basics Practice Tags : python Similar Reads Output of Python Programs | Set 19 (Strings) 1) What is the output of the following program? PYTHON3 str1 = '{2}, {1} and {0}'.format('a', 'b', 'c') str2 = '{0}{1}{0}'.format('abra', 'cad') print(str1, str2) a) c, b and a abracad0 b) a, b and c abracadabra c) a, b and c abracadcad d) c, b and a abracadabra Ans. (d) Explanation: String function 3 min read Structuring Python Programs In this article, you would come to know about proper structuring and formatting your python programs. Python Statements In general, the interpreter reads and executes the statements line by line i.e sequentially. Though, there are some statements that can alter this behavior like conditional stateme 7 min read Output of Python Program | Set 1 Predict the output of following python programs: Program 1:Python r = lambda q: q * 2 s = lambda q: q * 3 x = 2 x = r(x) x = s(x) x = r(x) print (x) Output:24Explanation : In the above program r and s are lambda functions or anonymous functions and q is the argument to both of the functions. In firs 2 min read Variables under the hood in Python In simple terms, variables are names attached to particular objects in Python. To create a variable, you just need to assign a value and then start using it. The assignment is done with a single equals sign (=): Python3 # Variable named age age = 20 print(age) # Variable named id_number id_no = 4067 3 min read Output of Python program | Set 5 Predict the output of the following programs: Program 1: Python def gfgFunction(): "Geeksforgeeks is cool website for boosting up technical skills" return 1 print (gfgFunction.__doc__[17:21]) Output:coolExplanation: There is a docstring defined for this method, by putting a string 3 min read Output of Python programs | Set 7 Prerequisite - Strings in Python Predict the output of the following Python programs. These question set will make you conversant with String Concepts in Python programming language. Program 1Python var1 = 'Hello Geeks!' var2 = "GeeksforGeeks" print "var1[0]: ", var1[0] # statement 1 print "var2[1:5 3 min read Output of Python Programs | Set 18 (List and Tuples) 1) What is the output of the following program? PYTHON L = list('123456') L[0] = L[5] = 0 L[3] = L[-2] print(L) a) [0, '2', '3', '4', '5', 0] b) ['6', '2', '3', '5', '5', '6'] c) ['0', '2', '3', '5', '5', '0'] d) [0, '2', '3', '5', '5', 0] Ans. (d) Explanation: L[0] is '1' and L[5] is '6', both of t 3 min read Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Uses of OS and Sys in Python In this article, we will see where we use Os and Sys in Python with the help of code examples. What is Os Module?Python OS module in Python furnishes a versatile means of engaging with the operating system. It facilitates a range of operations, including the creation, deletion, renaming, movement, a 4 min read Python String Input Output In Python, input and output operations are fundamental for interacting with users and displaying results. The input() function is used to gather input from the user and the print() function is used to display output.Input operations in PythonPythonâs input() function allows us to get data from the u 3 min read Like