Getting Started with Python: A Beginner’s Guide

Filipe Filardi
5 min readDec 25, 2022

--

Image by Clément Hélardot

Welcome to my introduction to Python written course! In this medium article series, you will learn the basics of programming using the Python programming language.

Python is a popular and powerful programming language widely used in various fields, including scripting, data analysis, and artificial intelligence. It is known for its simplicity, readability, and flexibility, making it an excellent choice for beginners and experienced programmers.

Before we can start writing Python programs, we must ensure that we have Python installed on your computer. In this article, we will cover how to install Python and help you get started with writing your first Python code.

Installing Python

Before you can start writing Python code, you’ll need to install it on your computer. Here’s how to do it on the three major operating systems:

Windows

To install Python on Windows, follow these steps:

  1. Go to the Python website and click the “Download for windows” button. Get the latest version available.
  2. A pop-up window will appear. Click on the “Save File” button to download the Python installer.
  3. Once the download is completed, double-click on the installer file to start the installation process.
  4. Follow the prompts to install Python on your computer. Check the box that adds Python to your PATH environment variable. This will make it easier to run Python from the command prompt.

Linux

To install Python on Linux, follow these steps:

  1. Open a terminal window.
  2. Type the following command and press Enter:
sudo apt-get update

3. Type the following command and press Enter:

sudo apt-get install python3

4. Wait for the installation to complete.

macOS

To install Python on a Mac, follow these steps:

  1. Go to the Python website and click the “Download for macOS” button. Get the latest version available.
  2. A pop-up window will appear. Click on the “Save File” button to download the Python installer.
  3. Once the download is complete, double-click on the installer file to start the installation process.
  4. Follow the prompts to install Python on your computer.

Writing Your First Python Program

Now that you have Python installed on your computer, it’s time to write your first Python program. The traditional first program for many programming languages is called “Hello World” which prints the phrase Hello, World! to the screen.

To write a “Hello, World!” program in Python, follow these steps:

  1. Open any text editor you like (such as Notepad on Windows or TextEdit on Mac).
  2. Type the following code:
print("Hello, World!")

3. Save the file as hello_world.py

That’s it! You’ve just written your first Python program.

Running your first Python program.

You’ll need to use the Python interpreter to run a Python program. The Python interpreter is a program that reads and executes Python code.

There are several ways to run a Python program, depending on your operating system and the tools you have installed. Here are a few options:

Using the Command Prompt (Windows) or Terminal (Mac/Linux)

If you are using Windows, open the Command Prompt by going to the Start menu and typing cmd in the search box. On a Mac or Linux machine, open the Terminal application.

Then, navigate to the directory where you saved your hello_world.py file using the cd (change directory) command. For example:

cd C:\Users\YourName\Documents\python

Once you are in the correct directory, type the following command and press Enter:

python hello_world.py

This will run the Python interpreter and execute the code in your hello_world.py file. You should see the message Hello, World! printed on the screen.

Using IDLE (Python’s Built-In IDE)

IDLE (Integrated Development and Learning Environment) is a simple IDE (Integrated Development Environment) that comes with Python. It provides a graphical user interface (GUI) for writing and running Python code.

To run your “Hello, World!” program using IDLE, follow these steps:

  1. Open IDLE by going to the Start menu and typing “IDLE” in the search box (on Windows) or by opening the Terminal and typing “idle3” (on Mac/Linux).
  2. Click on “File” and then “Open”.
  3. Navigate to the directory where you saved your hello_world.py file and double-click on it to open it in IDLE.
  4. Press the “F5” key to run the program. You should see the message “Hello, World!” printed on the IDLE shell window.

Running a Python Program in detail

When you run a Python program, the Python interpreter reads your code from top to bottom, executing each line as it goes. This is why the order of your code matters, as the interpreter will execute lines in the order they appear.

To save a Python program, create a new file with an .py extension and type your code into the file. You can use any text editor to create and edit Python files, such as Notepad, TextEdit, or Sublime Text.

Once you have saved your program, you can run it from the command line or terminal by entering the following command:

python3 my_program.py

Replace my_program.py with the name of your Python file. This will run your program and execute the code contained in the file.

Alternatively, as mentioned before, you can run a Python program within an integrated development environment (IDE). IDEs provide a more advanced environment for writing and debugging Python code, with features such as syntax highlighting code completion, and debugging tools.

This article covered Python programming basics, including installing Python on your computer and writing and running your first Python program.

In the following article, I’ll delve deeper into the topic of IDEs and explore the pros and cons of using one. I’ll also introduce you to some of the most popular IDEs for Python development and help you decide which is the best fit for your needs.

If you found this article helpful and would like to learn more about programming, consider subscribing.

Stay tuned, and let’s code!

If you’re interested in reading other articles written by me. Check out my repo with all articles I’ve written so far, separated by categories.

Thanks for reading

--

--

Filipe Filardi

Data Scientist with a passion for making Development and Data Science more accessible