Py+
💻 For developers

Python: Next Level

Functions, files, errors, OOP, and final projects — the sequel to «Python From Scratch»

What you'll build
📘A solid foundation
Practice in the browser
🎯Mini-projects
🎓Course certificate
📘 58 lessons1-2 evenings🎓 Advanced
🎯 Mission
Master Python: Next Level
+630XP
🏆CertificatePDF
🎓Course complete
Progress0 / 58 · 0%
Next up: What a function is and why you need it

Course program

01

Функции

0 / 12 lessons
  1. 01

    What a function is and why you need it

    def — declare a functionname() — call itCode reuse⚡ +10
    ▶ Now
  2. 02

    Parameters — passing data inside

    def f(name):Parameter and argumentAccess inside the function⚡ +10
    Open
  3. 03

    Multiple parameters

    def f(a, b)Order mattersComma between parameters⚡ +10
    Open
  4. 04

    return — returning a result

    return a valueCan store in a variableWithout return, a function returns None⚡ +10
    🔒 Pro
  5. 05

    Default parameters

    def f(x=10)Can call without an argumentRequired first, then defaults⚡ +10
    🔒 Pro
  6. 06

    Keyword arguments

    f(name=...)Order doesn’t matterHandy for long parameter lists⚡ +10
    🔒 Pro
  7. 07

    Local and global variables

    Inside a function — localOutside — globalLocal isn’t visible outside⚡ +10
    🔒 Pro
  8. 08

    *args — a variable number of arguments

    def f(*args)args is a tuplePass as many as you want⚡ +10
    🔒 Pro
  9. 09

    **kwargs — keyword arguments in a bundle

    def f(**kwargs)kwargs is a dictionaryFlexible settings⚡ +10
    🔒 Pro
  10. 10

    Lambdas — a function in one line

    lambda x: ...An anonymous functionWhen you need it for one action⚡ +10
    🔒 Pro
  11. 11

    Recursion — a function calls itself

    Base caseStep deeperWithout a base — infinity⚡ +10
    🔒 Pro
  12. 12

    Mini-project: a function library for a calculator

    4 functions with returnUsed in sequenceDefault parameters⚡ +10
    🔒 Pro
02

Файлы и ввод-вывод

0 / 10 lessons
  1. 13

    Files — what they are and why

    open(name, mode)Writing in "w"Closing the file⚡ +10
    🔒 Pro
  2. 14

    with — safe opening and auto-closing

    with open(...) as f:Body — indented 4 spacesClosing is guaranteed⚡ +10
    🔒 Pro
  3. 15

    Reading the whole file — read()

    Mode "r"f.read() → one big stringPrinting the contents⚡ +10
    🔒 Pro
  4. 16

    Reading line by line — for line in file

    for line in f:Each line separatelyrstrip() removes \n⚡ +10
    🔒 Pro
  5. 17

    Writing "w" — overwriting a file

    Mode "w" erases the oldwritelines for a listAdd the newline yourself⚡ +10
    🔒 Pro
  6. 18

    Appending "a" — adding to the end

    Mode "a" doesn’t eraseAdds to the endHandy for logs⚡ +10
    🔒 Pro
  7. 19

    encoding="utf-8" — Cyrillic and emoji without trouble

    By default — the system encodingencoding="utf-8" is universalWithout it you get «mojibake»⚡ +10
    🔒 Pro
  8. 20

    JSON — dictionary ↔ string

    json.dumps(data)json.loads(text)Handy for data exchange⚡ +10
    🔒 Pro
  9. 21

    JSON to a file — dump and load

    json.dump(data, f) — no sjson.load(f) — no sA file object, not a string⚡ +10
    🔒 Pro
  10. 22

    Mini-project: saving notes to JSON

    A list of dictionariesjson.dump to a filejson.load back⚡ +10
    🔒 Pro
03

Ошибки и исключения

0 / 8 lessons
  1. 23

    What an exception is

    A runtime errorThe program crashes with a tracebackBuilt-in error types⚡ +10
    🔒 Pro
  2. 24

    try / except — catching an error

    try: the risky codeexcept: what to do on an errorThe program does NOT crash⚡ +10
    🔒 Pro
  3. 25

    Several types in one except

    except (A, B):Several optionsA tuple of types in parentheses⚡ +10
    🔒 Pro
  4. 26

    else — run ONLY if there was no error

    try: we attemptexcept: we catchelse: everything went well⚡ +10
    🔒 Pro
  5. 27

    finally — always runs

    Runs after try/except/elseEven when returning from a functionUseful for cleaning up resources⚡ +10
    🔒 Pro
  6. 28

    raise — throwing your own error

    raise ValueError("...")When the input data is badSignalling «can’t go further»⚡ +10
    🔒 Pro
  7. 29

    Your own exception class

    class MyError(Exception):A clear name for a business errorraise + except as usual⚡ +10
    🔒 Pro
  8. 30

    Mini-project: a safe calculator

    A function with try/exceptraise for business rulesClear messages⚡ +10
    🔒 Pro
04

ООП

0 / 14 lessons
  1. 31

    What a class and an object are

    class — a templateAn object — a concrete instanceCreation via name()⚡ +10
    🔒 Pro
  2. 32

    __init__ and self — the object constructor

    __init__ runs automaticallyself is the object itselfself.attr = ... stores in the object⚡ +10
    🔒 Pro
  3. 33

    Multiple attributes

    Several self.x = ...Each object — with its own setCommas between __init__ parameters⚡ +10
    🔒 Pro
  4. 34

    Methods — functions inside a class

    def method(self)Call via object.method()You can use self.x inside⚡ +10
    🔒 Pro
  5. 35

    __str__ — a nice object representation

    By default — a technical formdef __str__(self) → stringprint() and f-strings call it⚡ +10
    🔒 Pro
  6. 36

    A list of objects — working with a collection

    Objects can go into a listfor loop over the listAccess each one’s attribute⚡ +10
    🔒 Pro
  7. 37

    A method that changes the object’s state

    self.attr = ... in a methodThe object «remembers» changesSeveral methods on one object⚡ +10
    🔒 Pro
  8. 38

    Class attributes — shared across all instances

    Declared DIRECTLY inside classWithout selfAccessed via ClassName.attr or self.attr⚡ +10
    🔒 Pro
  9. 39

    Private attributes — the _underscore convention

    _name — «don’t touch from outside»Not real protection, a conventionAccess via a method⚡ +10
    🔒 Pro
  10. 40

    Inheritance — class Cat(Animal)

    A child class gets the parent’s methodsclass Child(Parent):Free — whatever the parent has⚡ +10
    🔒 Pro
  11. 41

    super() — extending the parent constructor

    super().__init__(...)First the parent __init__Then your own self.x = ...⚡ +10
    🔒 Pro
  12. 42

    Overriding methods

    A child class can overwrite a parent methodSame name — different behaviorPolymorphism⚡ +10
    🔒 Pro
  13. 43

    Composition — an object inside an object

    An attribute can be an objectAccess via a chain of dotsAn alternative to inheritance⚡ +10
    🔒 Pro
  14. 44

    Mini-project: a bank account

    A class with methods and stateraise on an error__str__ for nice output⚡ +10
    🔒 Pro
05

Модули и стандартная библиотека

0 / 8 lessons
  1. 45

    What a module is and why you need it

    import math and othersAccess via math.pi / math.sqrtThe standard library⚡ +10
    🔒 Pro
  2. 46

    from ... import ... — taking only what you need

    from module import nameNo prefix in codeSeveral names via commas⚡ +10
    🔒 Pro
  3. 47

    as — giving a module a short name

    import name as shortUseful for long namesConventions like np / pd⚡ +10
    🔒 Pro
  4. 48

    random — random numbers

    randint(a, b) — an integer in a rangechoice(list) — a random elementEach run gives something different⚡ +10
    🔒 Pro
  5. 49

    datetime — date and time

    from datetime import datetimedatetime.now() — the current momentAttributes .year .month .day⚡ +10
    🔒 Pro
  6. 50

    math — advanced functions

    math.factorial(n)math.floor / math.ceilmath.gcd for GCD⚡ +10
    🔒 Pro
  7. 51

    collections.Counter — a counter out of the box

    from collections import CounterCounter(data) — frequencies.most_common(N) — top N⚡ +10
    🔒 Pro
  8. 52

    Mini-project: a password generator

    random.choices with kJoining via .joinLength — a function parameter⚡ +10
    🔒 Pro
06

Финальные мини-проекты

0 / 6 lessons
  1. 53

    Project: a TODO list with priorities

    A list of dictionariesadd_task / show_tasks functionsSorting by priority⚡ +10
    🔒 Pro
  2. 54

    Project: a currency converter

    Rates as a dictionaryconvert function via USDround rounding⚡ +10
    🔒 Pro
  3. 55

    Project: a notes diary in JSON

    A class with add / save / load methodsJSON for savingA loop over entries⚡ +10
    🔒 Pro
  4. 56

    Project: «Guess the number»

    random + whileA list of guessesHints higher / lower⚡ +10
    🔒 Pro
  5. 57

    Project: tracking books in a library

    Two classes: Book and Library__str__ for BookSearch by the author field⚡ +10
    🔒 Pro
  6. 58

    Финал: ToDo-менеджер с сохранением

    Класс TodoAppJSON для постоянстваВсе приёмы вместе
    Course complete
    🔒 Pro
Python: Next Level — online coding course