Python · Type Annotations

Does Optional[int] mean the argument is optional (can be omitted)?

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Type Annotations

What does this print, and does it raise? ``` def repeat(s: str, n: int) -> str: return s * n print(repeat(["P"], 3)) ```
True or false: adding type annotations makes Python check the argument types when a function is called, raising an error on a mismatch.
What is the correct syntax to annotate a function's parameters AND its return type?
What is Optional[X] equivalent to, written as a plain union?
How do you annotate a variable (with and without assigning a value)?
What does this print? ``` from typing import get_type_hints def f(x: int) -> str: return str(x) print(get_type_hints(f)) ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play