Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Function with type annotation

  • We can add type-annotations to the function parameters and even to the return value.
def add(x: int, y: int) -> int:
    return x + y

print("ok")
first = "19"
second = 23
print(add(first, second))
  • However, Python will disregard these type-annotations and we still get a run-time exception.