Python
A clear, friendly language for problem solving and automation
Learn Python step by step: data and strings, lists and dictionaries, functions, errors and files, and classes — and run every example right in your browser.
- 31 lessons
- 6 chapters
- Arabic & English
Your progress
What's inside
Lessons go from the basics to advanced topics. Read them in order, or jump to what you need.
Chapter 1
Getting Started
- 1Python IntroductionMeet Python: what it is, what it's used for, and why it's one of the best languages to start your programming journey.
- 2Get StartedInstall Python, check your version, run your first .py file from the terminal, and try commands instantly in the interactive REPL.
- 3Python SyntaxLearn the basic rules of writing Python: one statement per line, indentation to define blocks, and case-sensitive names.
- 4Python OutputDisplay text and values with print(), control separators and line endings with sep and end, and format your output neatly with f-strings.
- 5Python CommentsUse comments to explain your code, make it easier to read, and temporarily disable lines while testing.
Chapter 2
Variables & Data
- 6Python VariablesVariables are containers for storing data. Learn how to create them, name them correctly, and assign several values in one line.
- 7Python Data TypesEvery value in Python has a data type. Explore the built-in types for text, numbers, sequences, mappings, sets, and booleans, and check any value's type with type().
- 8Python NumbersWork with the three numeric types (int, float, and complex), use division, floor division, and the modulus operator, and round results with round().
- 9Python CastingConvert values from one type to another with int(), float(), and str(), an essential skill when working with user input and text.
- 10Python StringsCreate strings, access characters by index, slice parts of text, measure length with len(), combine and format strings with f-strings, and use escape characters.
- 11String MethodsPython strings come with built-in methods to change case, trim spaces, split and join text, replace words, search, and count.
- 12Python BooleansBooleans represent one of two values: True or False. Learn how comparisons produce booleans, how bool() evaluates values, and which values count as false.
- 13Python OperatorsOperators perform operations on values and variables. Learn the arithmetic, assignment, comparison, logical, membership, and identity operators.
Chapter 3
Collections
- 14Python ListsLists store multiple items in a single variable. Learn how to create them, access items with positive and negative indexes, slice them, change items, and loop through them.
- 15List MethodsAdd, remove, sort, and search list items with built-in methods such as append(), insert(), remove(), pop(), and sort().
- 16Python TuplesTuples are ordered collections that can't be changed. Learn how to create them, access items, unpack values into variables, and choose between a tuple and a list.
- 17Python SetsSets are unordered collections of unique items. Learn how to create sets, add and remove items, remove duplicates from your data, and use union, intersection, and difference.
- 18Python DictionariesDictionaries store data as key-value pairs. Learn how to access, add, update, and remove items, read values safely with get(), and loop through them with items().
Chapter 4
Control Flow
- 19Python If...ElseMake decisions in your code with if, elif, and else, combine conditions with and and or, nest conditions, and write one-line conditional expressions.
- 20Python MatchUse match and case (Python 3.10+) to compare a value against several patterns: a clean alternative to long if...elif chains.
- 21Python While LoopsRepeat code as long as a condition is true with the while loop, and control it with break, continue, and else.
- 22Python For LoopsLoop over lists, strings, and other sequences with for, generate number sequences with range(), and get indexes and pairs with enumerate() and zip().
Chapter 5
Functions & More
- 23Python FunctionsDefine reusable blocks of code with def, pass arguments, set default values, accept any number of arguments, and send results back with return.
- 24Python LambdaA lambda is a small anonymous function written as a single expression, perfect for short operations passed to functions like sorted(), map(), and filter().
- 25List ComprehensionCreate new lists from existing ones in a single, readable line with list comprehension, optionally filtering items and transforming their values.
- 26Python User InputRead what the user types with input(), convert it to numbers with int() and float(), read several values from one line, and validate the input.
- 27Python Try...ExceptHandle errors gracefully with try, except, else, and finally, catch specific exceptions, and raise your own errors with raise.
- 28Python ModulesOrganize and reuse code with modules: import built-in modules such as math and random, use from ... import and aliases, and create your own module.
- 29Python File HandlingCreate, write, append to, and read text files with open() and the with statement, learn the file modes, and delete files safely.
Chapter 6
Classes & Objects
- 30Python Classes and ObjectsPython is an object-oriented language. Learn how to define a class, create objects, initialize them with __init__(), use self, add methods, and control how objects print with __str__().
- 31Python InheritanceInheritance lets a class reuse the attributes and methods of another class. Learn how to create child classes, call the parent with super(), and override methods.