type
In Python, the type
soft keyword allows you to explicitly define generic type alias in the context of type hints or type annotations.
Python type
Keyword Examples
Here’s a quick example demonstrating how to use the type
keyword to define a type alias for either a list
or set
:
Python
type ListOrSet[T] = list[T] | set[T]
def function(values: ListOrSet):
pass
Python type
Keyword Use Cases
Defining generic type aliases.
Related Resources
Tutorial
Python Type Checking (Guide)
In this guide, you'll look at 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.
For additional information on related topics, take a look at the following resources:
- Python Keywords: An Introduction (Tutorial)
- Python Type Checking (Course)
- Python Type Checking (Quiz)
- Exploring Keywords in Python (Course)
- Python Keywords: An Introduction (Quiz)
By Leodanis Pozo Ramos • Updated May 23, 2025