Created
June 30, 2020 16:34
-
-
Save Rotzke/88098a56d9aa5bc0db8fda8a5f8e5a12 to your computer and use it in GitHub Desktop.
Dataclasses in Python 3.7+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class Card: | |
rank: str | |
suit: str | |
card = Card("Q", "hearts") | |
print(card == card) | |
# True | |
print(card.rank) | |
# 'Q' | |
print(card) | |
Card(rank='Q', suit='hearts') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment