No history yet

Introduction to Python

What Is Python?

Python is a powerful and versatile programming language, loved by beginners and experts alike. Think of it as a set of instructions a computer can understand. What makes Python special is its simple, clean syntax, which reads a lot like English. This design choice makes it easier to learn than many other languages.

Lesson image

It’s used almost everywhere. Companies like Google, Netflix, and NASA use it for a huge range of tasks. You can find Python powering websites, analyzing scientific data, automating repetitive tasks, and even creating artificial intelligence. Its massive collection of pre-written code, called libraries, means you don't have to start from scratch for every project.

Getting Set Up

To start writing Python, you need two things: the Python interpreter and a place to write your code. The interpreter is the core software that reads your Python code and translates it into instructions the computer can execute. It’s the engine.

You also need a code editor or an Integrated Development Environment (IDE). An IDE is a program that makes coding easier. It usually includes a text editor with syntax highlighting (coloring your code to make it readable), a way to run your code, and tools for debugging. For beginners, an IDE called Thonny is a great choice because it's simple and designed for learning.

Installing Python and Thonny is straightforward. You can download them from their official websites. Thonny for Windows and Mac even comes with Python bundled, so you only need one download.

Lesson image

Your First Program

A long-standing tradition in programming is to make your first program display the text "Hello, World!". Let's do that in Python. It only takes one line of code.

print("Hello, World!")

Here’s what’s happening:

  • print is a function. A function is a named block of code that performs a specific task. The print function's job is to display things on the screen.
  • The parentheses () after the function name are where you provide arguments—the information the function needs to do its job.
  • "Hello, World!" is the argument we gave to the print function. It's a string of text. The quotes tell Python that this is text, not a command.

To run this, you would open Thonny, type that line into the main editor window, save the file (e.g., as hello.py), and click the green 'Run' button. The output, Hello, World!, will appear in a panel called the Shell.

The Structure of a Script

A Python program, often called a script, is just a plain text file with a .py extension. The interpreter executes the commands in the file from top to bottom, one line at a time. Each line is a single instruction.

As your programs get more complex, you'll want to leave notes for yourself or others inside the code. You can do this with comments. A comment is a line of text that Python completely ignores. It’s just for human readers. To write a comment, you start the line with a hash symbol (#).

# This is a comment. Python will ignore this entire line.

print("This line will run.") # You can also add comments after code.

Comments are essential for explaining what your code does and why you wrote it a certain way. Good code isn't just about getting the computer to do something; it's also about making it understandable for people.

Quiz Questions 1/5

What is the primary reason Python is often recommended for beginners?

Quiz Questions 2/5

What is the role of the Python interpreter?

You've taken your first steps into Python. You know what it is, how to set it up, and how to write and run a simple program. From here, you can start exploring more of what the language can do.