Misunderstanding Python Class Attributes

I was attempting to assist on an open-source project when I was stopped short by this (names have been changed):class DataPoint: measurement1 = None measurement2 = None measurement3 = None DataPoint was later used like this:d = DataPoint() d.measurement1 = 100 d.measurement2 = 200 d.measurement3 = 300 Why give names and initialization values to class attributes, then when you make an object, immediately create and initialize instance variables with the same names as the class attributes?
 •  0 comments  •  flag
Share on Twitter
Published on May 10, 2022 17:00
No comments have been added yet.


Bruce Eckel's Blog

Bruce Eckel
Bruce Eckel isn't a Goodreads Author (yet), but they do have a blog, so here are some recent posts imported from their feed.
Follow Bruce Eckel's blog with rss.