Skip to content

Instantly share code, notes, and snippets.

@kaisugi
Created March 4, 2019 12:15
Show Gist options
  • Save kaisugi/c3560750b7a24ce51ad7961d975ab546 to your computer and use it in GitHub Desktop.
Save kaisugi/c3560750b7a24ce51ad7961d975ab546 to your computer and use it in GitHub Desktop.
Python 3.7で正式追加された @DataClass のサンプル
from dataclasses import dataclass
@dataclass(order=True)
class Human:
age: int
name: str
boy = Human(2, "suzuki")
girl = Human(3, "misaka")
print(boy) # Human(age=2, name='suzuki')
print(boy == girl) # False
print(boy < girl) # True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment