Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python type alias statements code

Practice creating type aliases, using aliases in annotations, and inspecting aliased type expressions.

Intermediate ~8 min read

Challenge 1

Create a type alias named Point for a pair of floating-point coordinates.

python Your answer

print(Point.__value__)

Press Ctrl⌘Enter to check your answer

Challenge 2

Create the Coordinates alias used by the function parameter.

python Your answer


def distance(point: Coordinates) -> float:
    x, y = point
    return (x * x + y * y) ** 0.5

print(distance((3.0, 4.0)))

Press Ctrl⌘Enter to check your answer

Challenge 3

Create an alias for a mapping from integer user IDs to user-name records.

python Your answer

users: UserTable = {1: (1, "Ada")}
print(users)

Press Ctrl⌘Enter to check your answer

Challenge 4

Create a type alias that refers to LaterName before LaterName is bound.

python Your answer

LaterName = str
print(FutureName.__value__)

Press Ctrl⌘Enter to check your answer