Predict the Output with Type Hints
Intermediate · Predict the output · from Python Type Hints: Add Types, Generics, and the typing Module
From the lesson: How Do You Simplify Complex Type Annotations?
When type annotations get long and repetitive, type aliases let you give them short, descriptive names. This keeps your code readable.
Read this part of the lessonWhat does this code print? Remember, type hints don't affect runtime behavior.
def add(a: int, b: int) -> int:
return a + b
result = add('hello', ' world')
print(result)
print(type(result).__name__)Write two print() statements with the exact output.
# Type hints don't enforce types at runtime!
# What actually gets printed?
print("?")
print("?")
More Type Hints exercises
- Add Type Hints to a FunctionIntermediate
- Type a Config FunctionIntermediate
- Type a Higher-Order FunctionIntermediate
- Add Runtime Type CheckingIntermediate
- Type a Data Processing FunctionAdvanced
All Python exercises · 50 practice problems · Advanced Python quiz