Introduction
A complete guide to Python — from your first line of code to advanced topics like async, decorators, and metaclasses.
Python
Python is one of the most popular programming languages in the world — and for good reason. It is simple enough for beginners to learn quickly, yet powerful enough to build real-world software used by companies like Google, Netflix, Instagram, and NASA.
This section covers Python from the ground up. Whether you have never written a line of code before, or you already know another language and want to learn Python, this guide is built for you.
What you will learn
Basics
Variables, data types, operators, input/output, and type conversion. Start here.
Control Flow
Making decisions with if, elif, else, and pattern matching with match/case.
Loops
for loops, while loops, and controlling them with break, continue, and else.
Functions
Defining functions, arguments, scope, lambda, decorators, and generators.
Data Structures
Lists, tuples, dictionaries, sets, strings, and comprehensions.
Object-Oriented Programming
Classes, inheritance, dunder methods, properties, and dataclasses.
Modules
Importing, the standard library, pip, and virtual environments.
File Handling
Reading and writing files, context managers, and pathlib.
Error Handling
Exceptions, custom errors, and debugging with logging and pdb.
Testing
Writing and running tests with unittest and pytest.
Advanced
Iterators, functional programming, type hints, and metaclasses.
Async
async/await, the event loop, and the asyncio module.
A quick taste of Python
Before diving in, here is what Python looks like. Do not worry about understanding everything yet — just notice how readable it is.
# A simple function that greets someone
def greet(name):
return f"Hello, {name}!"
print(greet("world")) # Hello, world!
# A list of numbers and a loop
numbers = [1, 2, 3, 4, 5]
for number in numbers:
if number % 2 == 0:
print(f"{number} is even")
else:
print(f"{number} is odd")Python reads almost like plain English. That is intentional — it is one of the core design goals of the language.
How Python compares to JavaScript
If you have already gone through the JavaScript section, here are the biggest differences to keep in mind:
| JavaScript | Python |
|---|---|
let x = 5 | x = 5 |
console.log() | print() |
Curly braces {} for blocks | Indentation (spaces) for blocks |
| Semicolons (optional) | No semicolons |
=== for equality | == for equality |
null | None |
true / false | True / False |
// comment | # comment |
Python uses indentation (spaces or tabs) to define code blocks instead of curly braces. This is not just style — it is required syntax. Inconsistent indentation causes errors.
Python versions
This guide uses Python 3.10+. Some topics (like match/case pattern matching) require Python 3.10 or newer. Python 2 is no longer supported and should not be used for new projects.
To check your version:
python3 --version
# Python 3.12.0Ready? Start with the Basics section.