No history yet

Introduction to Python

What is Python?

Python is a popular, high-level programming language known for its simple and readable syntax. It was created by Guido van Rossum and first released in 1991. The name comes from Monty Python's Flying Circus, a British comedy troupe, which gives you a hint about its fun and accessible philosophy.

One of Python's key features is its readability. The code often looks like plain English, which makes it easier for beginners to pick up. It's also an interpreted language. This means you can run your code line by line without needing a separate compilation step, which speeds up the development process. Think of an interpreter as a translator who translates your code into computer-readable instructions on the fly, one sentence at a time.

Lesson image

Python is incredibly versatile. It's used for web development, data analysis, artificial intelligence, scientific computing, and automation. This flexibility is supported by a massive standard library, which is a collection of pre-written code you can use to perform common tasks without having to write everything from scratch.

Getting Set Up

Before you can start writing Python code, you need to install it on your computer. The best place to get it is from the official website, python.org. You'll see options for different operating systems like Windows, macOS, and Linux.

Make sure you download the latest version of Python 3. An older version, Python 2, is no longer supported, so it's important to start with the current standard.

Lesson image

During installation on Windows, be sure to check the box that says "Add Python to PATH." This allows you to run Python from your computer's command line, which is a useful skill to have later on.

Once installed, Python comes with a simple program called IDLE (Integrated Development and Learning Environment). Think of an IDE as a workbench for programmers. It includes a text editor for writing code, tools for running it, and features to help you find and fix errors.

Lesson image

Your First Program

It's a tradition in programming to start by writing a program that displays "Hello, World!" on the screen. It's a simple way to confirm that your installation is working correctly. Let's do it using IDLE.

First, open IDLE. You'll be greeted by the Python Shell, which has a >>> prompt. This is an interactive environment where you can type Python commands and see the results immediately. At the prompt, type the following:

print("Hello, World!")

Press Enter, and you should see Hello, World! printed on the next line. Congratulations, you've just run your first line of Python code!

In this code, print() is a built-in function that tells the computer to display whatever is inside the parentheses. The text in quotes is called a string, which is how programmers represent text.

While the shell is great for testing small snippets, you'll usually write longer programs in script files. In IDLE, go to File > New File to open a blank text editor. Type the same command in this new window, and then save the file as hello.py. The .py extension is important because it tells the computer this is a Python script.

To run your script, go to Run > Run Module in the editor window (or press F5). The output will appear back in the Python Shell window.

Now that you have your environment set up and have run your first program, it's time to check your understanding.

Quiz Questions 1/5

What is the primary characteristic of an interpreted language like Python?

Quiz Questions 2/5

What is the standard file extension for a Python script file?