-
Book Overview & Buying
-
Table Of Contents
Metaprogramming with Python
By :
An object can be defined as the instance of the class. If we consider a class itself as a data type, then an object can be defined as the variable of a class of type ClassName.
A class without an object is practically unusable. All the attributes and methods created for the class can be effectively utilized once we create an object instance, as follows:
obj_name = ClassName()
Considering the earlier example of a Branch class, we can create and utilize its objects as follows:
branch_albany = Branch()
Now, branch_albany is an instance of theBranch class and all its attributes can be modified for this instance without impacting the attributes within the class definition of Branch. An instance is more like a copy of the class that can be utilized without affecting the class itself. Let’s take the following code as an example:
branch_albany.branch_id = 123
branch_albany.branch_street...