Skip to content

Commit

Permalink
Update cheat_sheet_py3.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadhamzajabbar567 authored Apr 17, 2024
1 parent 0570f71 commit b197264
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/source/cheat_sheet_py3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ Classes
a.foo = 42 # Works
a.bar = 'Ex-parrot' # Fails type checking
class User(BaseModel):
id:int
name:str = "John Doe"
signup_ts: datetime | None = None
friends: list[int] = []


external_data = {
"id": '24',
"name": "John Doe",
"signup_ts": "2017-06-01 12:22",
"friends": [1, "2", b"3"]
}
user = User(**external_data)
print(user)
print(user.id)
print(user.name)
When you're puzzled or when things are complicated
**************************************************

Expand Down

0 comments on commit b197264

Please sign in to comment.