April 2014
Beginner to intermediate
634 pages
15h 22m
English
We initialize an object by implementing the __init__() method. When an object is created, Python first creates an empty object and then calls the __init__() method for that new object. This method function generally creates the object's instance variables and performs any other one-time processing.
The following are some example definitions of a Card class hierarchy. We'll define a Card superclass and three subclasses that are variations of the basic theme of Card. We have two instance variables that have been set directly from argument values and two variables that have been calculated by an initialization method:
class Card: def __init__( self, rank, suit ): self.suit= suit self.rank= rank self.hard, self.soft ...