Type Hint

noun

say it: “TYP HINT” /taɪp hɪnt/

A note in Python code saying what type a variable, parameter or return value should be, such as price: float; Python doesn't enforce it, but editors and tools use it.

What is a type hint?

A type hint notes what type a variable, parameter or return value should be. Python doesn't enforce it, but editors and tools use it to catch mistakes early.

def total_price(price: float, quantity: int) -> float:
    return price * quantity

In a sentence

  • “The type hint -> float says total_price gives back a decimal number.”
  • “mypy read the type hints and caught a string passed as a quantity.”

Level: Freelancer · More Python terms at this level

Updated