# type statement creates a type alias# type Point = tuple[int, int] # Python 3.12+ syntax# Using typing module (works in all versions)from typing import TypeAlias
# Pre-3.12 type alias
Point: TypeAlias = tuple[int, int]
defdistance(p1: Point, p2: Point) -> float:
return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2) ** 0.5
p1 = (0, 0)
p2 = (3, 4)
print(f"Distance: {distance(p1, p2)}")
# type() as a builtin functionprint(f"type(42): {type(42)}")
print(f"type('hi'): {type('hi')}")
print(f"type([1]): {type([1])}")
Output
Click "Run" to execute your code
'type' is both a soft keyword (Python 3.12+) for type aliases and a builtin function for checking types. As a keyword, it creates cleaner type alias syntax.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?