Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question is really rather broad as classes and instances/objects are vital parts of object-oriented programming, so this is not really Python specific. I recommend you buy some books on this as, while initially basic, it can get pretty in-depth. <a href="http://en.wikipedia.org/wiki/Class-based_programming" rel="nofollow noreferrer">In essense</a>, however:</p> <blockquote> <p>The most popular and developed model of OOP is a class-based model, as opposed to an object-based model. In this model, objects are entities that combine state (i.e., data), behavior (i.e., procedures, or methods) and identity (unique existence among all other objects). The structure and behavior of an object are defined by a class, which is a definition, or blueprint, of all objects of a specific type. An object must be explicitly created based on a class and an object thus created is considered to be an instance of that class. An object is similar to a structure, with the addition of method pointers, member access control, and an implicit data member which locates instances of the class (i.e. actual objects of that class) in the class hierarchy (essential for runtime inheritance features).</p> </blockquote> <p>So you would, for example, define a <code>Dog</code> class, and create instances of particular dogs:</p> <pre><code>&gt;&gt;&gt; class Dog(): ... def __init__(self, name, breed): ... self.name = name ... self.breed = breed ... def talk(self): ... print "Hi, my name is " + self.name + ", I am a " + self.breed ... &gt;&gt;&gt; skip = Dog('Skip','Bulldog') &gt;&gt;&gt; spot = Dog('Spot','Dalmatian') &gt;&gt;&gt; spot.talk() Hi, my name is Spot, I am a Dalmatian &gt;&gt;&gt; skip.talk() Hi, my name is Skip, I am a Bulldog </code></pre> <p>While this example is silly, you can then start seeing how you might define a <code>Client</code> class that sets a blueprint for what a Client is, has methods to perform actions on a particular client, then manipulate a particular <em>instance</em> of a client by creating an object and calling these methods in that context.</p> <p>Sometimes, however, you have methods of a class that don't really make sense being accessed through an instance of the class, but more from the class itself. These are known as <a href="http://docs.python.org/library/functions.html#staticmethod" rel="nofollow noreferrer">static methods</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload