Creating code with Python

Photo by Chris Ried on Unsplash

Creating code with Python

·

3 min read

Installing Python

To write Python code, you first need to install the Python interpreter on your computer, which will translate the lines of code we write into machine code that the computer can understand.

In this article, I am going to follow the steps for installing Python on Windows. Once you land on the Python website, you have to go over the Downloads section and click on the button that says Python 3.11.3. The number 3.11.3 indicates the version of Python you are installing on your computer, for this reason, depending on the time you are reading this article, it could be a different version.

Verifying Python installation

After following the instructions for the installation, you have to verify whether the Python interpreter has successfully been installed on our computer. To do so, you have to click on the Windows button and type in Command Prompt or cmd. After pressing Enter, a new dark screen should be opened on your computer. To verify the installation, you have to type in the Command Prompt the command python --version. If the application replies with the version of the interpreter we downloaded, the installation has been successful. Since I installed Python a while ago, the version you will see in the image below is the version available at the time I downloaded it.

Installing Visual Studio Code

In addition to this, you need to find a proper place to write code, with the right tools and features. The place where you are going to write code is called a text editor; a software application used for writing, editing and saving text-based files. There are many text editors available, but the most widely used is called Visual Studio Code.

Visual Studio Code is a source code editor created by Microsoft for Windows, Linux, and macOS. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. VS Code has become a popular tool among developers due to its flexibility, ease of use, and wide range of extensions. With its user-friendly interface and customizable features, it has become a go-to choice for many developers to streamline their coding experience. The intuitive interface also allows developers to collaborate and share their work with others.

As for the Python interpreter, I am going to follow the steps for installing VS Code on Windows. If you open the link above or visit the official website of VS Code, you have to click on the Download for Windows button.

Creating the first Python program

Once you completed the download of VS Code and opened it, you have to create the file in which you will write the code. To do so, just press Ctrl + ò: this combination of keys will open the terminal. Here you can execute the command code hello.py. You have just created your first Python file, recognizable from the extension .py. In the text editor above, you can type print("hello, world"). This is a famous canonical program that nearly all coders write during their learning process.

To run the program, you will need to execute in the terminal the command python hello.py. This is the passage in which Python interprets the code you wrote and translates it into zeros and ones that the computer can understand. The output of running our program is hello, world. You have just created your first Python program. Hurray!