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

mypy generics - plain

  • We can use generics to say that we accept any type and we can use it to indicate that some other parameter or the return type will be the same type.
def do_something[T](x: T) -> T:
    return x

y = do_something(23)
print(y + 19)
#print(y + "19")