CHAPTER 73   •   PYTHON

Python Type Hints

Learn how to document expected variable and function types.

01 What is this?

Learn how to document expected variable and function types.

02 Syntax

Python Syntax
name: str = 'AIFA'

03 Example

Python Example
def add(a: int, b: int) -> int:
    return a + b

print(add(10, 20))

04 Important Points

Type hints improve code readability and tooling.

05 Common Mistakes

Type hints do not automatically enforce types at runtime.

06 Real World Use

Type hints are useful in larger Python projects.

07 Practice This Topic

Now try the example yourself in the AIFA Python Editor.

  • Read the example carefully.
  • Change the values.
  • Run the code.
  • Observe the output.
  • Try creating your own example.
Try It Yourself →