Python Tutorial
This Python tutorial teaches you the Python programming language from the very first line of code up to classes, error handling and modules. Every chapter is short, focused on one topic, and full of examples you can edit and run directly in your browser.
Python is a general-purpose language created by Guido van Rossum and first released in 1991. Today it is one of the most popular languages in the world, used by beginners writing their first script and by large companies running huge systems.
Your First Python Example
The classic first program prints a message to the screen. In Python that takes a single line. Click "Try it Yourself" to open the editor, change the text, and run it again.
print("Hello, World!")
print("Welcome to the Python tutorial")Hello, World! Welcome to the Python tutorial
What Is Python Used For?
Python is popular because the same language works in many different fields. Some common uses are:
- Web development with frameworks such as Django, Flask and FastAPI
- Data analysis and visualization with pandas, NumPy and Matplotlib
- Machine learning and artificial intelligence with scikit-learn, PyTorch and TensorFlow
- Automation and scripting: renaming files, sending reports, scraping web pages
- Testing, DevOps tools, command line programs and even small games
Why Learn Python?
Python code reads almost like plain English, so you spend your energy on solving the problem instead of fighting the syntax. It has a huge standard library ("batteries included") and hundreds of thousands of extra packages on PyPI.
Python also runs everywhere: Windows, macOS, Linux, a Raspberry Pi, and even inside a web page, which is how the examples on this site work. Because it is so widely used, Python skills are in demand for jobs in software, data and research.
A Slightly Bigger Example
Here is a taste of what you will be able to write after a few chapters. It stores a list of numbers, loops over them, and prints a short report. Do not worry about the details yet; each piece is explained later.
scores = [72, 88, 95, 61]
for score in scores:
if score >= 70:
print(score, "pass")
else:
print(score, "fail")
print("Average:", sum(scores) / len(scores))72 pass 88 pass 95 pass 61 fail Average: 79.0
What This Python Tutorial Covers
The chapters follow the order most people learn Python in. You start with the basics and build up step by step:
- Getting started, syntax, comments and variables
- Data types: numbers, strings, booleans and type casting
- Collections: lists, tuples, sets and dictionaries
- Control flow: if...else, while loops and for loops
- Functions, lambda functions and list comprehensions
- Classes, objects and inheritance
- Exceptions, modules and string formatting
- A final chapter of practice examples that combine everything
This tutorial uses Python 3 (the examples run on Python 3.12). Python 2 reached end of life in 2020, so everything you learn here is modern Python.
Frequently asked questions
Is Python good for beginners?
Yes. Python has a clean, readable syntax with very little boilerplate, so beginners can write useful programs quickly. It is the most common first language taught in schools and universities.
How long does it take to learn Python?
Most people learn the basics covered in this tutorial in a few weeks of regular practice. Becoming confident with libraries for web, data or AI usually takes a few more months of building projects.
Do I need to install Python to follow this tutorial?
No. Every example runs in your browser using Pyodide, a version of Python compiled for the web. Installing Python locally is still useful later for bigger projects, and the next chapter shows how.
Is Python free?
Yes. Python is open source and free to download, use and distribute, even for commercial projects.