...

/

Puzzle 29: Explanation

Puzzle 29: Explanation

Let’s learn about type annotations in Python.

We'll cover the following...

Try it yourself

Try executing the code below to verify the result:

Press + to interact
def add(a: int, b: int) -> int:
return a + b
val = add('1', '2')
print(val)

Explanation

Python 3 added support for type hints. As the name suggests, though, they’re only hints that are not enforced by the Python interpreter. The only thing Python does with these hints (sometimes called annotations) is to add them to ...