On this page
article
Type Narrowing
Narrow types with isinstance checks.
Category: typing
Problem
Narrow types with isinstance checks.
Solution
if isinstance(x, str):
print(x.upper())
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path