Loading video player…

Python Type Checking: Overview

In this course, you’ll learn about Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit way. Recent versions of Python allow you to specify explicit type hints that can be used by different tools to help you develop your code more efficiently.

In this tutorial, you’ll learn about:

  • Type annotations and type hints
  • Adding static types to code, both your code and the code of others
  • Running a static type checker
  • Enforcing types at runtime

You’ll go on a tour of how type hints work in Python and find out if type checking is something you want to use in your code. If you want to learn more, you can check out the resources that will be linked to throughout this course.

To download the code in this course, click the link below:

Download

Sample Code (.zip)

8.3 KB

00:00 Hi, my name’s Chris Bailey with Real Python. I’d like to welcome you to the video course Python Type Checking 101. Traditionally, types have been handled by the Python interpreter in a flexible but implicit way.

00:12 Recent versions of Python allow you to specify explicit type hints that can be used by different tools to help you develop code more efficiently. What will you learn in this tutorial?

00:23 You’ll learn about type annotations and type hints. You’ll learn about adding static types to your code, and then how to run a static type checker. You’ll also learn about enforcing types at runtime.

00:39 Let me go over the table of contents for you. The course starts with this intro and course overview. Then it’s a dive into dynamic versus static typing. Python is a dynamically typed language.

00:52 How does that make it different from a language with static types?

01:00 Next, you’ll get an introduction to duck typing.

01:07 Then you’ll start creating type hints and adding them to code. Following that, you’ll learn how you can do static type checking with the tool Mypy. Then, I’m going to show you the pros and cons of adding type hints to your code.

01:29 After that, you’ll dive into annotations and learn about how they’re related to type hints.

01:40 Then you’ll get a comparison with type comments, which is a way to add type checking to any version of Python—even legacy Python.

01:52 And then you’ll get a chance to play around with Python types by creating a simple card game and adding type hints for sequence types like lists, tuples, and dictionaries.

02:07 And finally, a conclusion and course review. Okay, it’s time to get started with the differences between dynamically and statically typed languages.

Become a Member to join the conversation.