Py
💻 For developers

Python From Scratch

8 topics, 80 lessons: variables, operators, strings, numbers, conditions, loops, lists, dictionaries, and mini-projects

What you'll build
📘A solid foundation
Practice in the browser
🎯Mini-projects
🎓Course certificate
📘 80 lessons1-2 evenings🎓 Intermediate
🎯 Mission
Master Python From Scratch
+850XP
🏆CertificatePDF
🎓Course complete
Progress0 / 80 · 0%
Next up: What is a variable

Course program

01

Переменные и типы

0 / 8 lessons
  1. 01

    What is a variable

    NameValueAssignment =⚡ +10
    ▶ Now
  2. 02

    Variable names

    snake_caseForbidden namesCase⚡ +10
    Open
  3. 03

    Integers (int)

    intArithmeticUnderscores in numbers⚡ +10
    Open
  4. 04

    Floats (float)

    floatDivision /Rounding round()⚡ +10
    🔒 Pro
  5. 05

    Boolean type (bool) and comparisons

    True / False==, !=, <, >, <=, >=and / or / not⚡ +10
    🔒 Pro
  6. 06

    The type() function

    type()<class '...'>When it helps⚡ +10
    🔒 Pro
  7. 07

    Type conversion

    int(x), str(x), float(x)input gives a stringValueError⚡ +10
    🔒 Pro
  8. 08

    Multiple assignment

    a, b = 1, 2Swap a, b = b, aUnpacking⚡ +10
    🔒 Pro
02

Операторы и значения

0 / 5 lessons
  1. 09

    The +=, -=, *= operators and others

    +=, -=*=, /=Counters and accumulation⚡ +10
    🔒 Pro
  2. 10

    None and its meaning

    None — «nothing»is None vs == NoneWhen None is returned⚡ +10
    🔒 Pro
  3. 11

    Constants and PEP 8 style

    UPPER_CASEA convention, not a banWhy⚡ +10
    🔒 Pro
  4. 12

    f-strings — formatting

    f"...{x}..."Expressions inside {}Better than + or %⚡ +10
    🔒 Pro
  5. 13

    Mini-project: a profile

    Several typesf-stringAccumulation⚡ +10
    🔒 Pro
03

Строки

0 / 11 lessons
  1. 14

    What is a string

    Quotes '' and ""Empty stringString vs number⚡ +10
    🔒 Pro
  2. 15

    Concatenation and repetition

    + joins strings* repeatsWhat does NOT work⚡ +10
    🔒 Pro
  3. 16

    String length len()

    len()Empty = 0Comparing length⚡ +10
    🔒 Pro
  4. 17

    Case: upper / lower / capitalize

    .upper().lower().capitalize() / .title()⚡ +10
    🔒 Pro
  5. 18

    Cleaning: strip / replace

    .strip().replace(a, b)Chained calls⚡ +10
    🔒 Pro
  6. 19

    Indexing and slices

    s[0]s[-1]s[1:5], s[::-1]⚡ +10
    🔒 Pro
  7. 20

    Search: find / in / count / startswith

    .find(sub)in operator.count(), .startswith()⚡ +10
    🔒 Pro
  8. 21

    split / join

    .split(sep) → listsep.join(list) → stringPaired operations⚡ +10
    🔒 Pro
  9. 22

    Escaping: \n, \t, \"

    \n — newline\t — tab\\ and \"⚡ +10
    🔒 Pro
  10. 23

    Multiline strings

    """..."""Preserving line breaksDocstring⚡ +10
    🔒 Pro
  11. 24

    Mini-project: a business card

    f-stringString methodsMultiline output⚡ +10
    🔒 Pro
04

Числа и математика

0 / 10 lessons
  1. 25

    Integer division //

    // — the integer partHalvingComparing / and //⚡ +10
    🔒 Pro
  2. 26

    Modulo — remainder %

    % — remainderEven/oddCyclicity⚡ +10
    🔒 Pro
  3. 27

    Exponentiation and roots

    **math.sqrtFractional powers⚡ +10
    🔒 Pro
  4. 28

    abs, min, max

    abs(x)min(a, b, ...)max(a, b, ...)⚡ +10
    🔒 Pro
  5. 29

    round() and float precision

    round(x, n)Banker’s rounding0.1 + 0.2⚡ +10
    🔒 Pro
  6. 30

    The math module

    math.pi, math.emath.floor / math.ceilmath.factorial, math.gcd⚡ +10
    🔒 Pro
  7. 31

    Random numbers with random

    random.randintrandom.randomrandom.choice⚡ +10
    🔒 Pro
  8. 32

    Formatting numbers in f-strings

    {x:.2f}{x:,}{x:>10}⚡ +10
    🔒 Pro
  9. 33

    int ↔ float conversions

    int(3.7)float(5)Data loss⚡ +10
    🔒 Pro
  10. 34

    Mini-project: bill calculation

    %, /, **round, absf-string with :,.2f⚡ +10
    🔒 Pro
05

Условия

0 / 10 lessons
  1. 35

    if and else — your first decision

    if cond:else:Colon and indentation⚡ +10
    🔒 Pro
  2. 36

    elif — several options

    elifif/elif/else chainOrder matters⚡ +10
    🔒 Pro
  3. 37

    Indentation and blocks

    4 spacesOne level — one blockIndentationError⚡ +10
    🔒 Pro
  4. 38

    Truthy / Falsy — what counts as True

    Falsy: 0, '', None, []Everything else — Trueif x: vs if x is None:⚡ +10
    🔒 Pro
  5. 39

    and / or / not in conditions

    and — bothor — at least oneShort-circuiting⚡ +10
    🔒 Pro
  6. 40

    The ternary operator

    a if cond else bInline ifWhen it fits⚡ +10
    🔒 Pro
  7. 41

    match / case (Python 3.10+)

    Comparing one variableFallback — the _ symbolSeveral options via |⚡ +10
    🔒 Pro
  8. 42

    Nested conditions

    if inside ifReadability depthCombining with and⚡ +10
    🔒 Pro
  9. 43

    Common mistakes in conditions

    = vs ==is vs ==Comparing floats⚡ +10
    🔒 Pro
  10. 44

    Mini-project: grading a score

    if/elif/elseTernaryf-string⚡ +10
    🔒 Pro
06

Циклы

0 / 12 lessons
  1. 45

    The for loop and range — repeating an action

    for x in range(N)Indented loop bodyWhat an iteration is⚡ +10
    🔒 Pro
  2. 46

    range with a start, stop and step

    range(start, stop)range(start, stop, step)Backward step step=-1⚡ +10
    🔒 Pro
  3. 47

    Looping over a string — letter by letter

    for c in stringEach iteration = one characterWhen you need the index — range(len)⚡ +10
    🔒 Pro
  4. 48

    The while loop — while the condition holds

    while condition:Change the variable insideInfinite loop — what it is⚡ +10
    🔒 Pro
  5. 49

    break — exiting a loop early

    break stops the loopHandy with searchOnly one level⚡ +10
    🔒 Pro
  6. 50

    continue — skip this iteration

    continue skips the restOn to the next iterationThe opposite of break⚡ +10
    🔒 Pro
  7. 51

    enumerate — index plus value

    enumerate(data)Unpacking into two variablesIndex from zero⚡ +10
    🔒 Pro
  8. 52

    zip — iterating two data sets in parallel

    zip(a, b)Stops at the shorter oneUnpacking pairs⚡ +10
    🔒 Pro
  9. 53

    Accumulator — summing and counting in a loop

    Accumulator variabletotal = total + xAverage = sum / count⚡ +10
    🔒 Pro
  10. 54

    Nested loops — a loop inside a loop

    for inside forThe inner runs fullyDouble indent — 8 spaces⚡ +10
    🔒 Pro
  11. 55

    Common mistakes in loops

    Off-by-one with rangeInfinite whileAccumulator not reset⚡ +10
    🔒 Pro
  12. 56

    Mini-project: FizzBuzz

    for + if/elif/elseDivisibility via %Order of checks⚡ +10
    🔒 Pro
07

Списки

0 / 12 lessons
  1. 57

    What a list is and how to create it

    A list — an ordered collectionThe literal [a, b, c]Length via len()⚡ +10
    🔒 Pro
  2. 58

    Indices — accessing an element by number

    Indices from 0Negative from -1IndexError if you go past the edge⚡ +10
    🔒 Pro
  3. 59

    Slices — taking a piece of a list

    [start:stop]stop NOT includedOmitting start or stop⚡ +10
    🔒 Pro
  4. 60

    append, extend, insert — adding elements

    append — to the endextend — several to the endinsert — at any position⚡ +10
    🔒 Pro
  5. 61

    remove, pop, del — removing elements

    remove(x) — by valuepop(i) — by index + returnsdel list[i] — by index⚡ +10
    🔒 Pro
  6. 62

    The in operator — checking membership

    x in list — True/Falsenot in — the inverse checkWorks with strings too⚡ +10
    🔒 Pro
  7. 63

    Looping over a list — visiting elements

    for x in listNo index needed by defaultRead-only in a simple loop⚡ +10
    🔒 Pro
  8. 64

    sort, sorted, reverse — sorting

    list.sort() changes in placesorted() returns a new onereverse=True for descending⚡ +10
    🔒 Pro
  9. 65

    List comprehension — a list in one line

    [expression for x in data]With an if conditionReplacing loop + append⚡ +10
    🔒 Pro
  10. 66

    split and join — between a string and a list

    str.split(sep) → listsep.join(list) → strBy default split on spaces⚡ +10
    🔒 Pro
  11. 67

    Nested lists — tables of rows and columns

    A list of listsAccess table[row][col]Loop over rows⚡ +10
    🔒 Pro
  12. 68

    Mini-project: number statistics

    Sum + averagemin / maxSearching a list⚡ +10
    🔒 Pro
08

Словари

0 / 12 lessons
  1. 69

    What a dictionary is and why you need it

    Key → value pairsThe literal {key: value}When instead of a list⚡ +10
    🔒 Pro
  2. 70

    Getting a value by key

    d[key] — strictd.get(key) — softKeyError if no key⚡ +10
    🔒 Pro
  3. 71

    Adding and updating pairs

    d[new_key] = ...Overwrite if the key existsOne syntax for add+update⚡ +10
    🔒 Pro
  4. 72

    Removing pairs — del and pop

    del d[key]d.pop(key) returns the valueKeyError if no key⚡ +10
    🔒 Pro
  5. 73

    Checking a key with in

    key in d → True/FalseBy default checks KEYSBefore d[key] to avoid an error⚡ +10
    🔒 Pro
  6. 74

    keys, values, items — three ways to look

    d.keys() — keysd.values() — valuesd.items() — pairs⚡ +10
    🔒 Pro
  7. 75

    Looping over a dictionary

    for k in d — keys onlyfor v in d.values()for k, v in d.items() — a pair⚡ +10
    🔒 Pro
  8. 76

    Nested dictionaries — a dict inside a dict

    Value = another dictionaryAccess d[a][b]Profiles / structures⚡ +10
    🔒 Pro
  9. 77

    Dict comprehension — a dictionary in one line

    {k: v for ... in ...}From a list to a dictWith an if condition⚡ +10
    🔒 Pro
  10. 78

    The counter pattern — counting repetitions

    d[k] = d.get(k, 0) + 1Accumulator + dictionaryThe most common pattern⚡ +10
    🔒 Pro
  11. 79

    setdefault — soft key creation

    d.setdefault(k, default)Creates if missingUseful for grouping⚡ +10
    🔒 Pro
  12. 80

    Mini-project: word frequency in text

    split → word listCounter dictionary via .getCounting unique ones
    Course complete
    🔒 Pro
Python From Scratch — online coding course