June 2017
Beginner to intermediate
274 pages
6h 49m
English
The final fundamental building block we're going to discuss in this section is classes. The word class is a synonym for category or type; in this case, it is referring to data values.
A class defines a new kind of data value by describing a set of internal data and operations for that type of data value. This is done primarily by defining a group of functions that make up the class. A special function called __init__ is used to set up the internal data for a new data value of this type, and the rest of the functions define the operations on an existing data value of this type:
class Frood: def __init__(self, age): self.age = age print("Frood initialized") def anniversary(self): self.age += 1 print("Frood is now {} years old".format(self.age)) ...Read now
Unlock full access