No history yet

Introduction to Python

What Is Python?

Python is a high-level programming language, which is a way of saying it’s designed to be easy for humans to read and write. Think of it like this: instead of giving a computer instructions in its native, complex language of ones and zeros, you write in a language that looks a lot like English. Python takes care of translating your instructions into something the computer can understand.

It was created in the late 1980s by a programmer named Guido van Rossum. He wanted a language that was powerful but also clean and easy to learn. Fun fact: he named it after the British comedy troupe Monty Python's Flying Circus, not the snake.

Lesson image

Python's simplicity and versatility have made it one of the most popular languages in the world. It’s used for everything from building websites and automating repetitive tasks to conducting complex data analysis and developing artificial intelligence.

The main goal of Python is to let you write code that is clear, logical, and easy to understand, both for yourself and for others who might read it later.

The Zen of Python

Python has a clear design philosophy, summed up in a collection of 19 guiding principles known as "The Zen of Python." You can actually see them by typing a special command into a Python environment.

import this

This command prints aphorisms like "Beautiful is better than ugly" and "Readability counts." These aren't just suggestions; they are the core ideas that shape the language. One of the most unique results of this philosophy is Python's use of indentation.

In many programming languages, you use curly braces {} or keywords to show which lines of code belong together in a block. Python, however, uses whitespace. Lines of code that are part of the same block are indented at the same level. This might seem strange at first, but it forces you to write code that is visually clean and easy to follow.

# In Python, indentation defines the code block.
if age > 18:
    print("You are an adult.") # This line is inside the if-block
    print("You can vote.")     # This line is also inside

print("This is always printed.") # This is outside the if-block

This focus on readability makes it easier to work in teams and maintain code over time. Python also supports several ways of writing programs, known as programming paradigms. You can write simple, step-by-step instructions (procedural), create reusable blueprints for objects (object-oriented), or treat computation like a series of mathematical functions (functional). This flexibility allows you to pick the best approach for the problem you're trying to solve.

Getting Started

To start writing Python, you first need to install it. Python is free and open-source. The official website, python.org, is the best place to get it.

  1. Go to python.org: Navigate to the "Downloads" section. The website will usually detect your operating system (Windows, macOS, or Linux) and suggest the best version for you.
  2. Download the Installer: Click the button to download the latest stable version of Python 3.
  3. Run the Installer: Once downloaded, run the file. On Windows, there's a very important step: make sure to check the box that says "Add Python to PATH" before you click "Install Now." This allows you to run Python from your computer's command line, which is a powerful text-based interface for controlling your system.
Lesson image

After installation, you can verify it's working. Open your command line application (Terminal on macOS, Command Prompt or PowerShell on Windows) and type python --version or python3 --version. If it prints a version number, you're all set.

Your First Program

Python comes with a built-in application called IDLE (Integrated Development and Learning Environment). It's a simple tool that lets you write and run Python code right away.

Open IDLE. You'll see a window with a >>> prompt. This is the Python shell, where you can type commands and see immediate results. Let's try the traditional first program, "Hello, World!"

print("Hello, World!")

Press Enter, and you should see Hello, World! printed back to you. The print() part is a function, a reusable piece of code that performs an action. In this case, it displays whatever you put inside the parentheses.

While the shell is great for testing small snippets, you'll write larger programs in files. In IDLE, you can go to File > New File to open a basic text editor. Write your code, save it with a .py extension (like my_program.py), and then press F5 or go to Run > Run Module to execute it.

Lesson image

As you advance, you might want a more powerful editor, often called an IDE (Integrated Development Environment). Tools like Visual Studio Code, PyCharm, and Thonny offer features like code completion, debugging tools, and better project management, making it easier to write and manage complex applications.

Quiz Questions 1/5

What is the primary characteristic of Python as a high-level programming language?

Quiz Questions 2/5

What does Python use to define blocks of code (e.g., the contents of a loop or function)?

That's your first look at Python. You've learned what it is, its core philosophy, and how to get it running on your own machine. From here, you're ready to explore the building blocks of the language.