Hey Guys, in this module, we will discuss what is a Python Interpreter, how we can run our code in python, and much more. We have already talked about Python environment setup in few systems.
So, let’s start and learn about the Python Interpreter.
What is a Python Interpreter?
Python executes the code line by line i.e., Python is an interpreter language. As we know the computer can’t understand our language, it can only understand the machine language i.e., binary language. So, the Python interpreter converts the code written in python language by the user to the language which computer hardware or system can understand. It does all the time whenever you run your python script.
We write the python code in any text editor and save the same file using the “.py” extension in our system. Now, how will this code run? There must be some application or program like “python” or “python3” that must be installed in your system, and this is their duty to run this python code. This type of program is called Interpreter.
Python does provide a python shell, which is used to execute a single command in python and display the result accordingly.
The Python interpreter first reads the command, then evaluates the command, prints the results, and then again loops it back to read the command and because of this only Python is known as REPL i.e., (Read, Evaluate, Print, Loop).
How to run Python Shell?
To run a python shell, follow the given steps below.
- Open the power shell or command prompt on windows, and terminal window on mac.
- Write python there and then press enter.
- A python prompt consisting of three greater than symbols i.e., “>>>” appears.
- Now, just enter the single statement and see the results accordingly. For example, enter a single statement like 3 + 2 or 3 * 2 and then press enter, the result will appear in the next line respectively.
This was all about executing a single statement but what happens if you want to execute multiple statements in a single run or you want to build some applications in python for that you need to follow the mentioned steps below.
- Open notepad or any text editor.
- Write the code using python language. For example:
print(“Welcome to Use My Notes”); print(“Notes simplified for learners”);
- Save that file using the “.py” extension.
- Open the shell or command prompt.
- Now navigate the command prompt to the path where you have saved the file, execute the command python file_name.py, and press enter.
Apart from these, many more python interpreters are available like you can go for an online python compiler. There are many online compilers available, in this case, you don’t need to install anything in your system, for accessing an online compiler follow the given steps.
- Open google.com
- Type online Python compiler. The list of compilers will be opened.
- Go for the first one and start typing your code there.
The main drawback of using an online compiler is that you can’t be able to save your code in your local machine or system. The code is available till the compiler is opened in your browser, and once the compiler is closed the code is lost.
Another interpreter is Jupyter notebook, spider, so accessing all these you need to install the anaconda in your system follow the given steps.
- Open https://docs.anaconda.com/anaconda/install/windows/
- Then click on windows installation.
- After installation is done, you can go for the Jupyter notebook there, and start coding.
I hope you all liked this module and must be very much excited to start your journey towards this wonderful programming language called python. So, stay connected with us, from the next module, we are going to move in more depth towards our learning. Until then stay safe, stay healthy, keep reading, enjoy coding!