Skip to content

Instantly share code, notes, and snippets.

@isabelcosta
Created March 13, 2021 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isabelcosta/c14c4c9a4a098a17807e5bda2df92ac3 to your computer and use it in GitHub Desktop.
Save isabelcosta/c14c4c9a4a098a17807e5bda2df92ac3 to your computer and use it in GitHub Desktop.
Python dataclass simple example
# https://docs.python.org/3/library/dataclasses.html
from dataclasses import dataclass
@dataclass
class Youtuber:
"""Class for defining youtubers."""
name: str
categories: list[str]
youtubers = []
youtubers.append(Youtuber("Chris Stuckmann", ["movie-reviews"]))
youtubers.append(Youtuber("Double Toasted", ["movie-reviews"]))
youtubers.append(Youtuber("The Fitness Marshall", ["fitness"]))
for youtuber in youtubers:
print(f"{youtuber.name}'s categories are: {youtuber.categories}")
@haelmj
Copy link

haelmj commented Mar 14, 2021

Very good example @isabelcosta🚀. I personally am only learning about this new feature/format. Time to do some exploring, thanks for sharing!!!

@isabelcosta
Copy link
Author

Aww thank you @haelmj 🙌 So nice someone other than me gets to learn from this gist/post 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment