Python ❤️

from collections import Counter

text = """
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
"""

words = text.lower().split()

for word, count in Counter(words).most_common():
    bar = "🐍" * count
    print(f"{word:8} {bar}")

I’m Andrey Gein

  • London-based → in Bremen for only a few Saturdays during the semester
  • I love Python!
  • Telegram: @andgein
  • I love Python!!! Ask me any questions about Python!!111
  • I used to be a software engineer, and now I’m an SRE
  • During my life and career, I’ve been using not only Python, but also C++ and C#, Java and JavaScript, Go, PHP, Perl and Bash, Delphi, Kotlin, Assembly, SQL,
    Ruby, Erlang, Objective-C, even Haskell, Prolog, R and Basic…
Andrey Gein
It’s me!

Our team

Lunch?

What is this course about?

  • It’s about Python! And Python is the best my favourite programming language!
  • I’m not going to teach you programming in general
  • Let’s focus on Python
    • Its model and idioms
    • The standard library and ecosystem
    • Software architecture, code quality, testing, debugging
  • I’m not going to teach basic Python syntax — please use documentation, LLMs, Google, …
  • Despite that, you must know all Python syntax by the end

You can read Python!

  • I can show you a Python function
    def fahrenheit_to_celsius(fahrenheit: float) -> float:
        return (fahrenheit - 32) * 5 / 9
    and you understand it, don’t you?
  • avg = sum(numbers) / len(numbers)
    You get the idea, right?
  • One more function:
    def cointoss(n,t):
        return (lambda a:"\n".join(str(i)+":\t"+"*"*a.count(i) for i in range(min(a),max(a)+1)))\
            ([sum(randint(0,1) for _ in range(n)) for __ in range(t)])

Our goals

After the course, I’d like you to be able to

  • open any Python code in the world and understand what it does
  • find a bug, write tests, suggest improvements
  • suggest code or architecture improvements
  • distinguish Pythonic code from non-Pythonic code
  • know when Python is a good choice and when it’s not
  • understand how Python (and CPython) works at a low level
  • know details of Python tooling: PyPI, venv, uv, …
  • feel comfortable talking about Python libraries: requests, HTTPX, Django, FastAPI, pandas, NumPy & SciPy, YAML, Pydantic, Black & Ruff & Pylint, …

Why learn Python when we have LLMs?

  • Likely the most controversial topic in education today
  • I can’t predict the future, but I’m seeing how LLMs and agents have changed the industry so far
  • And we still need a smart human in the loop
  • Geoffrey Litt: Understanding is the new bottleneck [text] [video]
  • Make the most of AI tooling
  • … but build your own understanding of concepts and your ability to read code and support systems
A computer can never be held accountable, therefore a computer must never make a management decision

Source: IBM training manual, 1979

Course structure

  • Lectures: September 5th, October 17th, November 14th
  • Seminars: once a week, Friday at 11:15
  • Homework: 3 practical assignments per semester
  • Labs: large tasks taking 3–4 weeks with a face-to-face walkthrough at the end
  • Exam: at the end
  • Everything above is mandatory to pass the class. Everything below is optional
  • Conference: choose a topic, plan and prepare the material, give a talk (late November)
  • Team contest: a Saturday competition in late October with no algorithmic or data-structure tasks, but it’ll be fun — details later, teams of three

It’s a lot! A detailed roadmap is at

python.andgein.ru

and in the LMS

Grading

  • Exam: 100 points
  • Bonus points: 20 for giving a talk at the conference, 10 for quizzes during seminars
  • Practice: 100 points during the semester
  • Python Gym: 10
  • Homeworks: 3 × 10
  • Labs: 2 × 30
  • Bonus points: 20 for participation and winning the team contest

LLM usage

  • General rule: please use all the modern technologies available to you
  • In particular, you can freely use LLMs and agents in Labs, when preparing a Talk, and in the Contest
  • You still need to understand everything in your Lab’s code and be able to present it
  • For Python Gym, seminars, and homework, you can ask an LLM any questions or search the internet
  • Ask “Why are strings immutable in Python?” rather than “Write code for this task”

Python is easy

Python is not simple, however. Simple ≠ easy

And it’s easy to learn Python

It’s not easy to master software engineering though

Pythonic

Checking whether a collection is empty

if items:
    print("There are items")
if len(items) > 0:
    print("There are items")

Iterating over a collection

for name in names:
    print(name)
for i in range(len(names)):
    print(names[i])

Building a list of squares

squares = []

for x in numbers:
    squares.append(x * x)
squares = [x * x for x in numbers]

Zen of Python, by Tim Peters

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren't special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one — and preferably only one — obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

Now is better than never.

Although never is often better than right now.

If the implementation is hard to explain, it's a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea — let's do more of those!

import this