No history yet

Introduction to Python

What Is Python?

Python is a programming language, which is a way to give instructions to a computer. It was created in the late 1980s by Guido van Rossum, who wanted to make a language that was easy to read and write. He named it after the British comedy troupe Monty Python, not the snake.

Think of Python as a set of building blocks. You can use these blocks to create websites, analyze data, automate repetitive tasks, or even build games. Its syntax, or the rules for writing it, is clean and simple. This makes it a popular first language for people new to coding.

The main reason Python is so widely used is its versatility. It's not just for one specific task; it’s a general-purpose language that can handle almost anything.

Lesson image

Getting Set Up

To start writing Python, you first need to install it on your computer. You can download the latest version from the official website, python.org. The installation is straightforward, much like installing any other software.

When you install Python, it comes with a simple program called IDLE (Integrated Development and Learning Environment). An IDE is like a workbench for a programmer. It gives you a place to write your code, test it, and fix any errors. IDLE is perfect for beginners because it's simple and comes bundled with Python, so there’s nothing extra to install.

Lesson image

Your First Script

Let's write your first piece of Python code. It's a tradition in programming to start by making the computer say "Hello, World!". In Python, this is incredibly simple. We use a built-in function called print() to display text on the screen.

print("Hello, World!")

You can run this code in two ways. First, you can open IDLE and type that line directly into the interactive window (the one with the >>> prompt) and press Enter. The computer will immediately print the message back to you.

Alternatively, you can create a new file, type the code, and save it with a .py extension, like hello.py. Then you can run the entire file. This is how you'll write longer, more complex programs.

Lesson image

Syntax and Indentation

Every language has grammar rules, and programming languages have syntax. Python's syntax is known for being clean and readable. One of the most important rules in Python is indentation, which refers to the spaces at the beginning of a line of code.

In many other languages, indentation is just for looks. In Python, it's mandatory. It's how Python knows which lines of code belong together in a block. For example, when you start writing code that makes decisions (like if statements), the indented lines underneath are the instructions to follow if the condition is true.

Using incorrect indentation is one of the most common errors for beginners. Python will give you an IndentationError if you get it wrong. The standard is to use four spaces for each level of indentation.

# This code will run
if 5 > 2:
    print("Five is greater than two!")

# This code will cause an error
if 5 > 2:
print("Five is greater than two!") # Missing indentation

Don't worry too much about this for now. Most code editors, including IDLE, automatically handle indentation for you. Just remember that it’s a key part of how Python works.

Quiz Questions 1/6

Who is the creator of the Python programming language?

Quiz Questions 2/6

In Python, indentation (the spaces at the beginning of a line) is optional and only used to make code look nice.

You've taken the first steps into the world of Python. You know what it is, how to get it running, and how to write a simple command. Now, you're ready to build on this foundation.