You are on page 1of 19

PYTHON

Power of Introspection Objects and Object Orientation

Power of Introspection
Object Code looking at other modules and functions in memory as objects. Getting information and manipulating.

Optional and Named Arguments


Default values for function arguments

Built In Function
type Function str Function dir Function callable Function

Object References
getattr function gives reference to a function without knowing its name until run time. Works on modules as well getattr as a Dispatcher

Filtering Lists
Filter expressions are evaluated and if true are included in the list

Lambda Functions
One line mini functions Function that takes any number of arguments and returns the value of a single expression

Classes and Objects


Class declaration Creating an object Setting an attribute Creating an attribute Deleting an attribute

Private Attributes
Exists within the scope of the class Syntactic way of variable hiding

Doc Strings
Allows programmer to place comments directly inline for the end user to view and for the editor and compiler to read

Self Object
Instance of the class that you are presently working upon within a class method Example : call -> a.class_name() Definition will be def class_name(self) :

Methods
Function that is defined within a class scope Special parameter called self which identifies the instance of the class that is being operated on by the method

Special Methods
Initialization and Termination __init__ allocates the object __del__ removes the reference of the object Can be modified to anything what we want it to do in the code

String Conversion
__str__ method The method can be overridden to create our own specialized string display

Inheritance
Deriving functionalities from one into another Purpose to write as little code as possible and use as much as possible from previous instances Changing functionality of the base class

Multiple Inheritance
Derive properties from more than one base class at a time

Using Super
Override functionality of a base class, but still use that information in the derived class Super() function finds the right class in the inheritance tree that implements the method which is required

Operator Overloading
Define how the operators for that class work

THANK YOU

You might also like