python terminology on classes
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Mon Jul 26 20:04:22 EDT 2010
On Mon, 26 Jul 2010 16:52:06 -0500, Peng Yu wrote:
> Could you please let me know what the equivalent terms for the following
> C++ terms?
>
> constructor
> destructor
> member function
> member variable
> virtual member function
> function
(1) Python new-style classes have a constructor __new__ and an
initialiser __init__. Some people describe both as constructors, but
that's strictly incorrect because the instance has already been
constructed by the time __init__ is called. (Old-style classes don't have
__new__, only __init__.)
(2) Python destructors are called __del__ , but you shouldn't use them
unless you really know what you are doing.
(3) "Member functions" are methods.
(4) "Member variables" are attributes. If you have to distinguish between
attributes which live on the instance from one that lives on the class,
"instance attribute" and "class attribute".
(5) I believe that all methods in Python are virtual.
(6) Function.
> I think that C++ "function" is equivalent to python "function" and C++
> "member function" is equivalent to python "method". But I couldn't
> locate where the original definitions of the corresponding python terms
> in the manual as these term appear many times. Could you please point me
> where to look for the definition of these python corresponding terms?
I believe you are right, but I can't find a definition of C++ "member
function" that makes sense. Can you please point me where to look for the
definition of these C++ terms?
I don't believe the Python Language Reference explicitly defines terms
such as "attribute" and "method", but the tutorial may help:
http://docs.python.org/tutorial/classes.html
Quote:
In C++ terminology, all class members (including the data members)
are public, and all member functions are virtual.
Note: although the docs occasionally use the term "members" for
attributes, it is considered more standard to use "attribute" or "method"
unless discussing data types defined at the C layer.
--
Steven
More information about the Python-list
mailing list