![]() ![]() Common practice says to use self, but technically you can use any word: You just have to stay consistent for the rest of the class. This is our initialization method, or how we build the ‘under the hood’ part of our class. Now the first function we pretty much always see when building a class is def _init_(self, etc). ![]() This is pretty straightforward we’re just telling our code that the object we’re about to build is a class. First we can name the general class with class Team(). Let’s look at the structure of the class above. With the NBA team example, I would want to make sure each team object has information about coaches, players, location, etc. With a class, you can set up all the background details you want all the objects of this type of class (say NBA teams) to have. I like to use classes when I will be using similar objects that differ slightly.
0 Comments
Leave a Reply. |