No history yet

Introduction to Python

What is Python?

Python is a programming language, a way for us to give instructions to computers. It was created in the late 1980s by a programmer named Guido van Rossum. His goal was to make a language that was powerful but also easy to read and write, even for beginners. The name, surprisingly, comes from the British comedy group Monty Python, not the snake.

Lesson image

Python's design philosophy emphasizes code readability. This means a well-written Python program looks a lot like plain English, which makes it less intimidating than many other languages. It’s also incredibly versatile. People use Python for everything from building websites and analyzing data to creating games and automating repetitive tasks.

Getting Set Up

Before you can start writing Python code, you need to install it on your computer. The official place to get it is the python.org website. You'll want to download the latest stable version available for your operating system, whether it's Windows, macOS, or Linux.

The installation is straightforward. One important tip for Windows users: during installation, make sure to check the box that says "Add Python to PATH." This will make it easier to run Python from your computer's command line.

When you install Python, it comes with a simple program called IDLE (Integrated Development and Learning Environment). Think of IDLE as a basic workshop where you can write and run your Python code. It includes a text editor for writing your programs and a way to execute them.

Lesson image

Your First Program

A long-standing tradition in programming is to make your first program display the words "Hello, World!" on the screen. It's a simple way to confirm that everything is set up correctly. In Python, this is incredibly easy.

The core of the program is the print() function. A function is a named command that performs a specific action. The print() function's job is to display whatever you put inside its parentheses.

# This is a comment. Python ignores lines starting with #.
# The line below tells the computer to display the text.

print("Hello, World!")

To run this, open IDLE, go to File > New File, and type that single line of code into the new editor window. Then, save the file (File > Save) with a name like hello.py. The .py extension is important; it tells the computer that this is a Python file. Finally, run your program by selecting Run > Run Module from the menu, or by simply pressing the F5 key.

If you see "Hello, World!" appear in a separate window, congratulations! You've just written and run your first Python program.

The Interactive Shell

Besides writing programs in files, Python also has an interactive shell. When you first open IDLE, you'll see a window with a >>> prompt. This is the shell. It's like a direct conversation with the Python interpreter.

You can type Python commands one at a time, and the shell will execute them immediately. It's a fantastic tool for testing small pieces of code or exploring how different commands work without having to save and run a full file.

Try it out! Type print("Hello again!") at the >>> prompt and press Enter. The text will appear right below your command.

You can also use it as a powerful calculator. Type 2 + 2 and press Enter. The shell will immediately respond with the answer.

>>> 2 + 2
4
>>> 100 - 30
70
>>> 5 * 8
40

The interactive shell is perfect for quick experiments. For anything more permanent or complex, you'll want to write your code in a .py file.

Quiz Questions 1/5

What was a primary goal of Python's creator, Guido van Rossum, when designing the language?

Quiz Questions 2/5

Which function is used in Python to display text or other values on the screen?

You've taken your first steps into the world of Python. You know what it is, how to get it running, and how to write a basic command. This is the foundation for everything that comes next.