Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Python Classes Date: Mon, 4 Aug 2014 22:44:09 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 35 Message-ID: References: NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1407192249 10413 166.84.1.1 (4 Aug 2014 22:44:09 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 4 Aug 2014 22:44:09 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:75712 In Shubham Tomar writes: > classes. I understand that you define classes to have re-usable methods and > procedures, but, don't functions serve the same purpose. > Can someone please explain the idea of classes If a function simply accepts some data, does some calculations on that data and then returns a value, then you don't need classes at all. An example of this might be the square-root function: pass it any number and it calculates and returns the square root with no other data needed. But classes do come in handy for other sorts of uses. One classic example is employees at a company. Each employee has a name, ID number, salary, date of hire, home address, etc. You can create an Employee class to store those data items along with methods to manipulate those data items in interesting ways. The data items are specific to each separate Employee object, and the methods are shared among the entire class. > Can someone please explain what *things *like "__init__", "Object" > and "self" mean ? __init__() is the initializer method, which is called as one step of creating a class object. Object is the lowest-level class. All other classes inherit from Object. Within a class, self is a reference to the current class instance. -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.