What is a static attribute versus a dynamic attribute in classes?
What is a static attribute versus a dynamic attribute in classes?
So yesterday I learned (but I was too busy at and after work) to write it about what the difference between a static attribute or a dynamic attribute in a class is.
So let us define a class.
class LanaDelReySong:
artist = "Lana del Rey"
def __init__(self, name: str, artist: str):
self.name = name
So in this instance is:
- The artist name, or "Lana del Rey", is a STATIC CLASS ATTRIBUTE.
BUT THEN:
yosemite = LanaDelReySong(name="Yosemite")
dance_tile_we_die = LanaDelReySong(name="Dance Til We Die")
white_dress = LanaDelReySong(name="White Dress")
All three of these song names are DYNAMIC CLASS ATTRIBUTES.
THEY CHANGE WITH EVERY INSTANCE OF THE CLASS.
SO NO MATTER WHAT, A LANA DEL REY SONG ALWAYS HAS THE ARTIST OF LANA.
BUT THE NAMES OF THE SONG TITLES WILL CHANGE EVERY TIME.
Comments
Post a Comment