Skip to content

Instantly share code, notes, and snippets.

@OhkuboSGMS
Created November 19, 2022 11:14
Show Gist options
  • Save OhkuboSGMS/abe735cdd9408b11c82a6603c5ac2e2e to your computer and use it in GitHub Desktop.
Save OhkuboSGMS/abe735cdd9408b11c82a6603c5ac2e2e to your computer and use it in GitHub Desktop.
eq=True and fronze=True has __hash__ function
from dataclasses import dataclass
@dataclass(frozen=True)
class Params:
user_name: str
age: int
weight: float
if __name__ == '__main__':
a = Params('Alice', 12, 34.5)
b = Params('Bob', 40, 70.9)
c = Params('Bob', 40, 70.9)
print(hash(a)) # 6475419868813917241
print(hash(b)) # -312248743948144481
print(hash(c)) # -312248743948144481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment