Complete the code to define a Pydantic model with a single field 'name' of type string.
from pydantic import BaseModel class User([1]): name: str
The Pydantic model must inherit from BaseModel to work properly.
Complete the code to add an integer field 'age' to the Pydantic model.
from pydantic import BaseModel class Person(BaseModel): name: str age: [1]
string or float for age.bool by mistake.The field age should be an integer, so use int as the type.
Fix the error in the Pydantic model by completing the missing import.
from pydantic import [1] class Product(BaseModel): id: int price: float
The BaseModel class must be imported from Pydantic to define models.
Fill both blanks to define a Pydantic model with a required string field 'title' and an optional integer field 'year'.
from pydantic import BaseModel from typing import [1] class Movie(BaseModel): title: str year: [2][int] = None
List or Dict instead of Optional.Optional.Use Optional from typing to mark year as optional.
Fill all three blanks to define a Pydantic model with a field 'tags' that is a list of strings with a default empty list.
from pydantic import BaseModel, [1] from typing import [2] class BlogPost(BaseModel): tags: [2][str] = [3](default_factory=list)
list[str] without importing List.Field for default values.Use Field to set defaults and List from typing to type the list of strings.