Python allows introspection, or the ability to treat code as objects that can be examined and manipulated at runtime. It uses objects and object-oriented programming. Functions can take optional and named arguments with default values. Built-in functions like type, str, dir, and callable provide information about objects. Attributes can be accessed and functions dispatched dynamically using getattr. Lambda functions are anonymous one-line functions. Classes define objects through attributes and methods. Methods have a self parameter to access instance attributes. Special methods like __init__ and __str__ control object initialization and representation as a string. Classes can inherit from other classes and override methods while still accessing the parent implementation using super(). Operators can be overloaded to work on custom classes.
2. Power of Introspection
• Object
• Code looking at other modules and functions
in memory as objects.
• Getting information and manipulating.
3. Optional and Named Arguments
• Default values for function arguments
arguments.py
4. Built In Function
• type Function type.py
• str Function
• dir Function str.py
• callable Function
dir.py
callable.py
5. 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
reference.py
6. Filtering Lists
• Filter expressions are evaluated and if true are
included in the list
filtering.py
7. Lambda Functions
• One line mini functions
• Function that takes any number of arguments
and returns the value of a single expression
lambda.py
8. Classes and Objects
• Class declaration
• Creating an object
• Setting an attribute jeff_class.py
• Creating an attribute
• Deleting an attribute
9. Private Attributes
• Exists within the scope of the class
• Syntactic way of variable hiding
private.py private_access.py
10. Doc Strings
• Allows programmer to place comments
directly inline for the end user to view and for
the editor and compiler to read
doc.py
11. 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) :
12. 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
method.py
13. 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
init.py
14. String Conversion
• __str__ method
• The method can be overridden to create our
own specialized string display
string.py
15. 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
inheritance.py
17. 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
super.py