Created
March 13, 2021 20:13
-
-
Save isabelcosta/c14c4c9a4a098a17807e5bda2df92ac3 to your computer and use it in GitHub Desktop.
Python dataclass simple example
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
# 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}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aww thank you @haelmj 🙌 So nice someone other than me gets to learn from this gist/post 🤗