Skip to content
Devtoolry

Python Examples

Classic Python programs, each with the code, its exact output, a step-by-step explanation, the mistakes people make and a few exercises. Every output was produced by running the program.

Each example opens in the online Python Compiler with one click, so you can change it and run it straight away, or press Visualize step by step to watch the program run line by line with its variables and call stack. Everything runs in your browser, with nothing to install.

Also available: JavaScript Examples.

Basics

Input, arithmetic and if/else: the first programs everyone writes.

Numbers

Primes, factorials, Fibonacci and other loops over digits and divisors.

Strings

Reversing, counting and comparing text.

Lists and algorithms

Searching, sorting and working with lists.

Patterns and small projects

Nested loops and complete little programs.