R

Ravina • 3.96K Points
Extraordinary

Q. What is the correct way to make a parameter optional with a default value in FastAPI?

  • (A) def read_item(id: int = None)
  • (B) def read_item(id: Optional[int] = None)
  • (C) def read_item(Optional id: int)
  • (D) def read_item(id?: int)
  • Correct Answer - Option(B)
  • Views: 27
  • Filed under category Fast API
  • Hashtags:

Explanation by: Ravina

Use `Optional[int] = None` for an optional parameter with a default value.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.