12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5. self is the name commonly given to the first (leftmost) argument in a classmethod function; <strong>Python</strong> automatically fills it in with the instance object that isthe implied subject of the method call. This argument need not be called self;its position is what is significant. (Ex-C++ or Java programmers might prefer tocall it this because in those languages that name reflects the same idea; in<strong>Python</strong>, though, this argument must always be explicit.)6. Operator overloading is coded in a <strong>Python</strong> class with specially named methods;they all begin and end with double underscores to make them unique. These arenot built-in or reserved names; <strong>Python</strong> just runs them automatically when aninstance appears in the corresponding operation. <strong>Python</strong> defines the mappingsfrom operations to special method names.7. Operator overloading is useful to implement objects that resemble built-in types(e.g., sequences or numeric objects such as matrixes), and to mimic the built-intype interface expected by a piece of code. Mimicking built-in type interfacesenables you to pass in class instances that also have state information—i.e.,attributes that remember data between operation calls. You shouldn’t use operatoroverloading when a simple named method will suffice, though.8. The _ _init_ _ constructor method is the most commonly used; almost everyclass uses this method to set initial values for instance attributes and performother startup tasks.9. The special self argument in method functions and the _ _init_ _ constructormethod are the two cornerstones of OOP code in <strong>Python</strong>.480 | Chapter 23: Class Coding Basics

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!