Skip to content

Python Annotations

New Course Coming Soon:

Get Really Good at Git

Python is dynamically typed. We do not have to specify the type of a variable or function parameter, or a function return value.

Annotations allow us to (optionally) do that.

This is a function without annotations:

def increment(n):
    return n + 1

This is the same function with annotations:

def increment(n: int) -> int:
    return n + 1

You can also annotate variables:

count: int = 0

Python will ignore those annotations. A separate tool called mypy can be run standalone, or integrated by IDE like VS Code or PyCharm to automatically check for type errors statically, while you are coding, and it will help you catch type mismatch bugs before even running the code.

A great help especially when your software becomes large and you need to refactor your code.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Get my Python Handbook
→ Get my Python Handbook

Here is how can I help you: