
Explore Python's multifaceted type system, from duck typing to static typing, and learn how and why to use type hints, protocols, and type checkers to prevent runtime errors.
Understand how type systems prevent errors and invalid state, enable modular interfaces, and frame Python’s dynamic, implicit, nominal typing with static checking and protocol classes.
Explore how types define data kinds, permissible operations, and safe memory use in modern languages, with Python's role and the rise of static typing.
Explore Python's built-in types, including integers, floats, booleans, strings, lists, tuples, dictionaries, and date time, and learn how implicit typing and classes influence dynamic typing.
Examine how Python uses literals versus class instantiation for int, float, and string, how type errors arise from conversions, and how left-hand operand rules influence error messages.
Explore how literals in Python drive automatic type inference, with number literals (ints, floats, complex), string literals, and raw or escaped strings, including binary, octal, and hexadecimal forms.
Explore how Python binds names to objects, revealing local scope, namespaces, and aliasing, and contrast dynamic typing with static concepts like manifest types.
Explore how class instances store attributes and methods, how the instance, class, and type namespaces interact, and how vars and dunder dict reveal the object's structure for self.
Explore the differences between dynamic and static typing, including how dynamic variables reference objects and how static types enable compile-time checks, with duck typing and Python's runtime behavior explained.
Explore duck typing in Python, where code uses an object's attributes and methods instead of its type. Learn how dynamic typing enables rapid prototyping and gradual typing with type hints.
Explore how Python's datamodel uses dunder methods like __str__ to provide printable objects and predictable behavior. Understand duck typing, protocols, and how type errors guide you toward idiomatic, reliable code.
Explore how Python's bytecode compiler and interpreter cache pyc files to speed loading, contrasting with architecture-specific compilers that use static types for optimization.
Learn how type hints annotate parameters and return types in Python, how static type checking evolved with pep 484 and mypy, and how tools like pyrite support gradual typing.
Demonstrate how type hints annotate function parameters and return types, enabling a static type checker to catch mismatches before runtime and guide code correctness.
Explore common sequence and mapping types in Python, including lists, tuples, and dictionaries, and learn how type hints and the type checker enforce element types, mutability, and variance.
Explore advanced special typing constructs in Python, including any and union types, type guards and refinement, nullable values with none, and callable objects for callbacks.
Explore composite data types by building classes that group attributes, apply type hints, and resolve forward references while comparing dynamic and static type checking in Python.
Compare dynamic typing, where types are stored in objects and checked at runtime. Contrast static typing, where types are declared in source code and checked by compilers or static checkers.
Explore how type system concepts define safety and behavior. Distinguish trapped versus untrapped errors and clarify casting versus conversions across languages like Python, JavaScript, and C.
Explore how a type system balances soundness and completeness, using gradual typing and static checks in Python, C#, and TypeScript to prevent runtime errors.
Examine the Python type system from duck typing to static and dynamic typing, showing how promotion and demotion, operator overloading, and runtime checks yield safe, predictable results.
Explore how Python compares types using the is operator, the None checks, and the single instance of None. Then distinguish nominal and structural typing to structure programs.
Explore nominal and structural typing, compare nominal subtyping by class name with protocol based structural subtyping, and see how protocol classes enable static type checking in Python.
Decouple code by replacing the switch on employee types with polymorphism and protocol classes, avoid circular dependencies, and apply static type checking and dependency injection for scalable Python projects.
Discover how type systems shape programming languages, from duck typing to static typing, and explore design decisions behind where languages belong, with diagrams and an accompanying e-book.
Advance beyond duck typing and the Python data model by supporting Python protocols with special methods. Watch free chapters of the Python data model online course and enroll.
In Python, it's easy to overlook types. You can simply write a = 10, and it works without needing to specify its type. However, beneath Python’s simple and intuitive syntax lies a surprisingly complex type system. In fact, as you'll discover in this course, Python integrates multiple type systems to manage data and behavior effectively.
You might ask—why study types at all? After all, you probably use them every day in Python without thinking much about it. And that’s true: it’s entirely possible to write functioning code without understanding the details of how the type system works. But, as with many aspects of software engineering, gaining a deeper understanding of the how and why allows you to make smarter, more intentional design decisions in your code and systems.
Target audience
Developers who especially benefit from this course, are:
Beginners and intermediates who want to know the mechanics and purpose of types and type systems in Python
Software engineers who want to use the type system as an extra development tool by adding type hints to improve their code quality
Developers who want to learn the proper terminology to make discussing code in your team and searching for information online more efficient
Challenges
Python is an easy language to learn. It hides many of the nuances about data types. But when developers get more experienced, they are more confronted with Python’s unique way to create, instantiate and work with data types. It is at this moment where it helps to take a deep dive into Types and Type Systems.
What can you do after this course?
Fix bugs faster by understanding error messages better
Prevent common type problems by knowing type system techniques
Make classes more efficient by using Python’s unique language features
Create clean modular design by using Protocol classes and type hints
Discuss pro’s and con’s of proposed solutions by learning proper technical terms
Make the transition from another language to Python more efficient
Topics
Introduction to type systems: Type system categories and their basic building blocks: types.
Implicit vs. explicit typing: Literals, variables and attributes.
Dynamic vs. static typing: Duck typing, Python protocols and the Python Datamodel, Compilers and interpreters.
Type Hints: Annotations, static type checkers, kind of types, special typing constructs.
Type flexibility: Safe, sound, complete. Promotion, conversion and comparison.
Nominal vs. structural typing: Using composite classes and protocols to design interfaces for modular systems.
Duration
3 hours video time.
The teacher
This course is taught by Loek van den Ouweland, a senior software engineer with 30 years of professional experience. Loek is the creator of Wunderlist for windows, Microsoft To-do and Mahjong for Windows and loves to teach software engineering.