dogs = Dog(birthday=date.today(), weight=6.66, sound=[{'sound': 'w w~~'}, {'sound': 'y y~~'}]) print(dogs.dict()) >> {'birthday': datetime.date(2021, 12, 1), 'sound': [{'sound': 'w w~~'}, {'sound': 'y y~~'}]}
下面这样写 weight 才对吧 class Dog(BaseModel): birthday: date weight: Optional[float] sound: List[Sound]
老师的写法是 weight: float = Optional[None]
我猜是这样的,具体两个什么区别,不知道呢