No history yet

Introduction to Python

What Is Python?

Python is a popular, versatile programming language. Think of it as a set of instructions a computer can understand. Unlike some languages that are very rigid and technical, Python is designed to be readable and straightforward. Writing Python code is often compared to writing in English because its syntax is clean and simple.

Lesson image

It was created in the late 1980s by Guido van Rossum, who wanted to make a language that was both powerful and easy to learn. Fun fact: it's named after the British comedy troupe Monty Python, not the snake.

Python's popularity comes from a few key features:

  • Readability: The code is clean and easy to follow.
  • Simplicity: It requires fewer lines of code to perform tasks compared to many other languages.
  • Versatility: You can use it for almost anything, from building websites and analyzing data to creating games and automating repetitive tasks.

Python is used by companies like Google, Netflix, and NASA for everything from web servers to machine learning.

Setting Up Your Workspace

To start writing Python, you need two main tools: the Python interpreter and a code editor.

The interpreter is the program that reads your Python code and carries out its instructions. It translates your commands into a language the computer's hardware can execute. You can download the latest version for free from the official Python website, python.org. Many operating systems, like macOS and Linux, even come with Python pre-installed.

A code editor is a text editor designed for writing code. While you could use a basic program like Notepad, specialized editors offer features like syntax highlighting (coloring your code to make it more readable) and auto-completion. A great place to start is with IDLE, a simple editor that comes bundled with the standard Python installation.

Lesson image

For your very first program, you don't even need to install anything. You can use one of the many free online Python editors available right in your web browser. This is a great way to try things out without any setup.

Your First Program

A long-standing tradition in programming is to make your first program display the message "Hello, World!". It's a simple way to confirm that your setup is working and to see a basic command in action.

In Python, this is incredibly easy. All you need is the print() function. A function is a reusable block of code 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 print() function displays text to the screen.
print("Hello, World!")

Let’s break that down. print is the name of the function. The parentheses () are used to pass information to the function. In this case, we're passing it the text "Hello, World!". The quotation marks tell Python that this is a string of text, not another command to be interpreted.

When you run this code, the interpreter sees the print() function and displays the string inside the parentheses. The output will simply be:

Hello, World!

That's it. You've just written and executed your first Python program. This single line demonstrates the simplicity and power of the language. You gave the computer a clear instruction, and it did exactly what you told it to do.

Quiz Questions 1/5

What is the primary design philosophy behind Python's syntax?

Quiz Questions 2/5

What is the role of the Python interpreter?

You now know what Python is, what it's used for, and how to write a basic command. This is the first step on your journey into programming.