mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-09 18:50:34 -05:00
Included optional arguments
This commit is contained in:
parent
51978ba13c
commit
d9942249cd
1 changed files with 3 additions and 1 deletions
|
@ -13,7 +13,7 @@ from dataclasses import dataclass
|
|||
@dataclass
|
||||
class Person:
|
||||
name: str
|
||||
age: int
|
||||
age: int = 0
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
@ -27,3 +27,5 @@ print(p)
|
|||
Person(name='Bob', age=20)
|
||||
```
|
||||
|
||||
To make an attribute have a default value, add it after the type declaration like I have with `age`.
|
||||
|
||||
|
|
Loading…
Reference in a new issue