Python-05 (Python OOPS)
Python-05 (Python OOPS)
OOP Terminology
Class: A user-defined prototype for an object that defines a set of
attributes that characterize any object of the class. The attributes are
data members (class variables and instance variables) and methods,
accessed via dot notation.
Class variable: A variable that is shared by all instances of a class.
Class variables are defined within a class but outside any of the
class's methods.
Data member: A class variable or instance variable that holds data
associated with a class and its objects.
Function overloading: The assignment of more than one behavior
to a particular function. The operation performed varies by the types
of objects or arguments involved.
Instance variable: A variable that is defined inside a method and
belongs only to the current instance of a class.
OOP Terminology
conti
Example-01
Special method,
which is called class
constructor or
initialization method.
It create a new
instance of this
class.
Example-02
Class Inheritance
Class
Base1
Class
Base2
Class Base4
Class
Base5
Class
Base3
Class Attributes
In Python, Built-In
built-in attributes
can be accessed
using dot operator
__dict__:
namespace.
__doc__:
undefined.
__name__:
Class name.
isinstance(obj,
Class)
Sample call
obj=ClassNa
me(args)
del obj
str(obj)
cmp(obj,x)
repr(obj)
Data Hiding
An object's attributes may or may not be visible
outside the class definition.
You need to name attributes with a double underscore
prefix.
Double underscore
for data hiding
Operators Overloading