Skip to content

Instantly share code, notes, and snippets.

@Rotzke
Created June 30, 2020 16:34
Show Gist options
  • Save Rotzke/88098a56d9aa5bc0db8fda8a5f8e5a12 to your computer and use it in GitHub Desktop.
Save Rotzke/88098a56d9aa5bc0db8fda8a5f8e5a12 to your computer and use it in GitHub Desktop.
Dataclasses in Python 3.7+
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