No history yet

Introduction to Python

What is Python?

Python is a popular, high-level programming language created by Guido van Rossum and first released in 1991. Its design philosophy emphasizes code readability with its notable use of significant indentation. Think of it as a language that wants you to write clean, logical code for projects big and small.

Lesson image

One of Python's key features is that it's an interpreted language. This means you don't need to compile your code before running it. An interpreter runs through the program line by line and executes each command directly. Imagine giving a chef a recipe one step at a time versus giving them the whole recipe book at once. The chef who gets instructions one by one is like an interpreter.

This line-by-line execution makes Python great for beginners because you can quickly see the results of your code and debug errors as they happen.

Getting Set Up

First, you need to install Python on your computer. Many macOS and Linux systems come with Python pre-installed. To check, open your terminal or command prompt and type python --version. If it's not there, or if you're on Windows, you can download the latest version from the official Python website, python.org.

Lesson image

When you install Python, it also comes with a simple development environment called IDLE (Integrated Development and Learning Environment). You can write and run your code directly in IDLE, which is great for starting out. As you get more advanced, you might switch to a more powerful code editor like VS Code or PyCharm, but for now, IDLE is all you need.

Lesson image

Your First Program

It's a tradition in programming to start by making the computer say "Hello, World!". Let's do that in Python. Open IDLE or a plain text editor, create a new file, and save it as hello.py. The .py extension is important—it tells the computer this is a Python file.

In that file, type the following line:

print("Hello, World!")

Here, print() is a built-in function that tells Python to display whatever is inside the parentheses on the screen. The text inside the quotes is called a string.

To run your program, you can either select 'Run Module' from the 'Run' menu in IDLE, or navigate to your file in the terminal and type python hello.py. You should see the output Hello, World! appear.

Understanding Python's Structure

Python's syntax is known for being clean and readable. One of the most unique aspects of Python is how it uses whitespace. Unlike many other languages that use curly braces {} to define blocks of code, Python uses indentation.

In Python, indentation isn't just for style—it's a rule. This consistency makes it easier for anyone to read your code.

Look at this simple example. The print() statement is indented, which tells Python it belongs to the if statement and should only run if the condition is true.

temperature = 30

if temperature > 25:
    print("It's a warm day!") # This line is indented

The standard is to use four spaces for each level of indentation. Most code editors will automatically do this for you when you press the Tab key.

Another part of Python's structure is comments. Anything following a hash symbol (#) on a line is a comment. The interpreter ignores it completely. Comments are for humans—they help you and others understand what your code is doing.

Now that you've got the basics down, let's test your knowledge.

Quiz Questions 1/5

What is a primary design philosophy of the Python programming language?

Quiz Questions 2/5

Python is an interpreted language, which means the code is run line by line without needing a separate compilation step.

Congratulations on writing your first Python program! You've taken the first step into a much larger world of coding.