Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75720

Re: Python Classes

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'languages,': 0.04; 'syntax': 0.04; 'python)': 0.05; 'subject:Python': 0.06; 'definitions': 0.07; 'level,': 0.07; 'purpose.': 0.07; '"class"': 0.09; '(its': 0.09; 'classes.': 0.09; 'constructor': 0.09; 'defines': 0.09; 'explicitely': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'screen.': 0.09; 'python': 0.11; 'blocks': 0.16; 'closed,': 0.16; 'data)': 0.16; 'indirectly': 0.16; 'parts.': 0.16; 're-usable': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Classes': 0.16; 'language': 0.16; 'library': 0.18; 'module': 0.19; 'drawing': 0.19; 'unlike': 0.19; 'example': 0.22; 'programming': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; '(such': 0.24; 'helpful': 0.24; 'together.': 0.24; 'define': 0.26; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'function': 0.29; '(this': 0.29; 'related': 0.29; 'moved': 0.30; "i'm": 0.30; 'serve': 0.31; 'usually': 0.31; 'writes:': 0.31; 'class': 0.32; 'quite': 0.32; 'level.': 0.33; 'classes': 0.35; 'common': 0.35; 'something': 0.35; 'objects': 0.35; 'operate': 0.35; 'operations': 0.35; 'but': 0.35; 'building': 0.35; 'leads': 0.36; 'charset:us-ascii': 0.36; 'similar': 0.36; 'application': 0.37; 'operating': 0.37; 'level': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'most': 0.60; 'simple': 0.61; 'first': 0.61; 'received:217': 0.63; 'such': 0.63; 'more': 0.64; 'between': 0.67; 'anything.': 0.68; 'containing': 0.69; 'stated': 0.69; 'construction': 0.72; 'potentially': 0.81; '"delete",': 0.84; 'around,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From dieter <dieter@handshake.de>
Subject Re: Python Classes
Date Tue, 05 Aug 2014 08:37:11 +0200
References <CAGOccLnM=n4evSGYeEwURbAOpT2LKskdSsCts9ojCwwbFd39ig@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e09d60.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:6M6fFwW2CXyLr/eNrdSoHXkgq8Y=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12661.1407220648.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407220648 news.xs4all.nl 2893 [2001:888:2000:d::a6]:40055
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75720

Show key headers only | View raw


Shubham Tomar <tomarshubham24@gmail.com> writes:
> Python is the first programming language that I'm learning.
> I'm confused by the idea of classes and intimidated by syntax defining
> classes. I understand that you define classes to have re-usable methods and
> procedures, but, don't functions serve the same purpose.

As often, you may have building blocks at various levels.
Thinks of a house - you can build it from individual stones or
have large prefabricated parts.
Something similar is true with functions and classes.

A function is a building block at some level.
However, often, you deal not with individual unrelated functions but
with a set of related functions designed together.

In simple cases, those functions can be collected in a library or
a module (Python's "math" module is such an example - containing
many interesting "mathematical" functions).

In other (slightly more complicated) cases, the relation between
the functions is that they all work on the same "object".

Those "object"s can be almost anything. An example would be
a "window" on your desktop screen. It can be closed, resized, moved around, ...
Or a "geometric object" in a drawing application - with operations
"delete", "move", "resized", "extend", ...

In those cases, it can be helpful to view the object (its data)
and the functions operating on it (such as "move", "resize", ...)
as a higher level building block -- and this leads to classes.

A "class" (in Python) is a collection of related functions (called
"method"s) and potentially data definitions (this part is quite
weak for Python classes; unlike in other languages, the data part
of a class is not stated explicitely at the top class level, but
usually indirectly in the so called constructor ("__init__")).
Most of these functions operate on the same data. Data and functions
together are called an "object" and the "class" defines a set
of objects of some common kind: "window"s, "date"s, "server"s,
"geometric object"s ...


This higher level building block can facilitate the construction
of many applications.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Classes dieter <dieter@handshake.de> - 2014-08-05 08:37 +0200

csiph-web