No history yet

Python Basics

What Is Python?

Python is a popular, high-level programming language. Think of it as a set of instructions a computer can understand, but written in a way that’s closer to human language. It’s known for being readable and relatively simple to learn, which makes it a great choice for beginners.

Lesson image

Despite its simplicity, Python is incredibly powerful. It’s used for everything from building websites and automating repetitive tasks to conducting scientific research and developing artificial intelligence. Companies like Google, Netflix, and Instagram use Python extensively in their operations.

A Quick History

Python was created in the late 1980s by a Dutch programmer named Guido van Rossum. He wanted to design a language that was easy to read and write. The name doesn't come from the snake, but from the British comedy group Monty Python's Flying Circus, which Guido was a fan of.

Python’s core philosophy is centered on code readability and simplicity. The idea is that code is read far more often than it is written, so it should be clean and easy to understand.

One of its key features is that it's an interpreted language. This means you can run your code line by line as soon as you write it, without a separate compilation step. This makes testing and debugging much faster. It's also dynamically typed, which simply means you don't have to tell Python what kind of data a variable will hold ahead of time. The language figures it out for you.

Getting Started

First, you need to install Python on your computer. Many Mac and Linux systems come with Python pre-installed, but it might be an older version. It's always best to get the latest stable version directly from the official website, python.org.

For Windows, you can download an installer that guides you through a simple setup process. Be sure to check the box that says "Add Python to PATH" during installation. This small step makes it much easier to run Python from your command line.

Lesson image

Once installed, you can interact with Python in two main ways:

  1. The Interactive Interpreter: This is a tool (often called a shell or REPL) that lets you type Python commands one at a time and see the results immediately. It’s great for testing small snippets of code.
  2. Script Files: For anything more complex, you'll write your code in a file (usually with a .py extension) and then tell Python to run that file. This is how you'll build actual programs.

Your First Program

Let's write the traditional first program: "Hello, World!" It's a simple program that just prints that phrase to the screen. Open your command prompt or terminal and type python (or python3 on some systems) and press Enter. You should see a >>> prompt. This is the interactive interpreter. Now, type this:

print("Hello, World!")

When you press Enter, Hello, World! will appear on the next line. You’ve just run your first line of Python code.

Now, let's do it with a script file. Open a plain text editor (like Notepad on Windows or TextEdit on Mac) and type the same line. Save the file as hello.py. Make sure it's saved as a plain text file, not a rich text file. Then, navigate to the folder where you saved it in your terminal and run it with this command:

python hello.py

The same message, Hello, World!, will be printed to your terminal.

Lesson image

As you start writing more code, you'll notice a few things about Python's structure. First, whitespace matters. Specifically, indentation is used to define blocks of code, like loops or functions. Unlike other languages that use curly braces {} or keywords, Python uses clean indentation. This forces you to write code that's easy to read.

You can also add comments to your code to explain what it does. In Python, anything on a line after a hash symbol (#) is a comment and is ignored by the interpreter.

# This is a comment. It won't be executed.
print("This line will be executed.")

That's it for the absolute basics. You've learned what Python is, where it came from, how to install it, and how to write and run a simple program. This foundation is the first step toward building much more complex and interesting things.