No history yet

Introduction to Python

What is Python?

Python is a programming language known for its simple, readable syntax. It’s often compared to writing in English, which makes it a fantastic starting point for anyone new to coding. But its simplicity is deceptive; Python is incredibly powerful and versatile.

Lesson image

Programmers use Python for a huge variety of tasks. Some of the most common applications include:

  • Web Development: Building the server-side logic of websites and web apps.
  • Data Science & Machine Learning: Analyzing large datasets, creating visualizations, and training artificial intelligence models.
  • Automation: Writing scripts to automate repetitive tasks, like organizing files or sending emails.
  • Software Development: Creating all sorts of applications, from video games to productivity tools.

Getting Set Up

To start writing Python, you need two things: the Python interpreter and a place to write your code. The interpreter is a program that understands your Python code and executes its instructions. For writing code, you'll use an Integrated Development Environment, or IDE.

An IDE is like a word processor specifically for code. It helps you write, test, and run your programs, often with helpful features like syntax highlighting and debugging tools. We’ll use Thonny, an IDE designed for beginners.

The best part about Thonny is that it comes with Python already bundled. By installing Thonny, you're also installing Python, so you can get started right away.

To install it, simply go to the official Thonny website (thonny.org), download the installer for your operating system (Windows, Mac, or Linux), and run it. The setup process is straightforward.

Lesson image

Your First Program

It's a long-standing tradition in programming to make your first program display the text "Hello, World!" on the screen. Let's do that now.

Open Thonny. You'll see two main parts. The top area is the script editor, where you write your code. The bottom area is the Shell, where you'll see the output of your program.

In the script editor at the top, type the following line of code.

print("Hello, World!")

Let's break this down. print() is a built-in Python function. A function is a named block of code that performs a specific task. The print() function's task is to display text on the screen.

The text you want to display goes inside the parentheses () and must be enclosed in quotation marks "". This tells Python that it's a piece of text, also known as a string.

Running Your Script

Before you can run the code, you need to save it. Go to File > Save and name your file hello.py. The .py extension is important, as it tells the computer that this is a Python script.

Now, to run your program, just click the green "Run current script" button in the toolbar (it looks like a play button). You should see the text Hello, World! appear in the Shell at the bottom of the window.

Lesson image

That's it! You've written and executed your first Python program.

Ready to check your understanding?

Quiz Questions 1/5

What is the primary role of an IDE (Integrated Development Environment) like Thonny?

Quiz Questions 2/5

Which of the following lines of code will correctly display the text Hello, World! on the screen?

You've taken the first step into the world of programming. Next, we'll start exploring some of Python's fundamental building blocks.