🤔How does python work? What is the simple way to execute the Python code immediately?

Koay Yong Cett
7 min readJun 15, 2020

Before understanding how python actually work, you must first understand what is a programming language?

  • Programming is simply a way for us to give instructions to computers. We give it an instruction manual and the computer follows.
  • Without code, computer programs wouldn’t do anything. For instance, you wouldn’t be able to move the mouse around on your screen and Google things.
  • We can’t just tell our computer what to do? This is because computers don’t understand English or any other language for that matter.

How can we communicate with computers?

  • So what language does computer speak? Well, they speak in ones and zeros where all electronics speak that language 🔈 “on and off” or “0 and 1”. However, it would be gibberish for us if we write a 0 and 1. It is hard for us to communicate in this way.
  • Therefore, humans have developed a programming languages that are in between the human language and machine language.
  • Some programming languages are lower level than others where they are closer to machine language. While other programming languages are higher level than others which they are closer to English or human language.
  • There are lots of programming languages. For instance, languages like assembly that is really close to machine code. In addition, languages such as Python and JavaScript are really close to English.

Now what are we missing in between?

  • Now, we have the programming languages that we usually write on a file such as Python, JavaScript and Java etc.
  • Somehow, we need to get these written files into ones and zeros that our machines can understand.
  • The code that we write using the programming language which is referred as source code will be given to the translator that understands this language as well as the machine language.
  • The translator will translates all these files for us. So actually what is this translator? It is definitely not a person right? 😏

Ready to have your mind blown about that translator we mentioned before?

  • Well it is another program written by a human and it can either be an interpreter or a compiler. In addition, Python usually uses an interpreter to perform this action.
  • Interpreter is similar to a translator where it goes line by line through our code and executes our code on our machine.
  • Compilers is a bit of different where they take your code all at once, read entire file all at once and then translate to the machine code.

I want you all to have the general picture that when we write code whether it’s Python, JavaScript, Java, C or C++. What we are doing is we’re simply typing it in a language that is human readable and give it to the interpreter or compiler. It will yield the codes that are able to execute on our machine.

In previous section, we learned that we need a interpreter or compiler in order to write Python code . How can we get these?

🌐 We download it from the website: https://www.python.org

  • Before we start downloading the Python 3.8.3 from the website, let’s understand what is the idea of downloading the translator (interpreter or compiler).
  • For the translation machines, we can have tons of different interpreters and different compilers.
  • For instance, when you click the download button at the python.org site, you are actually downloading the cpython. The interpreter is referred as “cpython” as it is written in the C programming language.
  • It’s a program written in C to read your Python file and executes it on a machine. There are other implementations existed in nowadays.
  • Here, we have Jython which is a translator that is written in Java language.
  • PyPy is another translation machine that is written in Python.
  • Next, we also have the IronPython which is written for the .NET framework.

The idea behind downloading Python from the python.org website:

  • When you are downloading the Python, the official language associated with it is actually cpython. It means that you are downloading this interpreter that follows the Python specification which is the language itself.
  • In conclusion, you are downloading the interpreter which is a machine built by somebody and it comes in many forms such as Jython, PyPy and IronPython etc.
  • Therefore, when people talk about Python, they are talking about the implementation which is the cpython that performs the translation for us.

Let’s get into the details of the flow:

  • We are actually downloading a machine that take our code and transfer to the interpreter which we downloaded using cpython.
  • Then, the cpython will create a byte code. For instance, the byte code here prints “hello world” on our screen. This looks pretty confusing just for printing the hello word.
  • The interpreter does that automatically for us and it’s happening behind the scene.
  • Once the byte code is created and it is closer to the machine code, the CPYTHON VM then executes the byte code and the byte code gets executed on our machine such as mobile phones, computers and laptops etc.

How to run Python ?

There are many tools can be used to run the Python code. These tools performs best in certain field of works. There are a lot of installation and configuration needed if you want to use all this.

How we get started right away no matter what device you are on?

Instead of downloading all these application and software, we can proceed to the repl.it and the site link is https://repl.it/login .

  • I recommend to create an account on here and trust me it’s going to be very useful. This is one of the efficient tool that allows you to save Python files online.
  • Once you create a new account and login, you can just create a new repl with the language Python and name it whatever you want to.
  • Without ever downloading the translation service(python in python.org) that I mentioned before, we can now start writing the Python code in our browser.
  • This is going to work for anyone else that has an internet connection as the interpreter here is run automatically.
  • The fantastic function with the ripple here is that you can save the files and have different folders saved.
  • We can organize all the python files and have them nicely organized. In addition, we can access from anywhere as long as the internet connection is available.

There is another Alternatives if you don’t like repl.it due to any reason:

  • You can also use this open source glot.io to run the python code after choosing the python programming language.
  • Here you go, you successfully run Python.

Thanks for reading my stories 😄

--

--

Koay Yong Cett

A Bachelor CS student with major in Network Security (UniSZa). Every stories I shared is based on my personal opinion. Thanks you. Having my Internship now.