In all our python programs till now, we have designed our program
around functions or blocks of statements which manipulate data. This is
called the procedure-oriented way of programming. There is another way
of organizing your program which is to combine data and functionality
and wrap it inside what is calledan object. This is called the object
oriented programming paradigm.
Before move to advance, let's Overview of 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. Class variables aren't used as frequently as instance variables are.
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 (arguments) involved.
Instance variable: A variable that is defined inside a method and belongs only to the current instance of a class.
Inheritance : The transfer of the characteristics of a class to other classes that are derived from it.
Instance: An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
Instantiation : The creation of an instance of a class.
Method : A special kind of function that is defined in a class definition.
Object : A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.
Operator overloading: The assignment of more than one function to a particular operator.
Python is fully object-oriented: you can define your own classes, inherit from your own or built in classes, and instantiate the classes you've defined.The self Class methods have only one specific difference from ordinary functions - they must have an extra first name that has to be added to the beginning of the parameter list, but you do do not give a value for this parameter when you call the method, Python will provide it. This particular variable refers to the object itself, and by convention, it is given the name self.Although, you can give any name for this parameter, it is strongly recommended that you use the name self - any other name is definitely frowned upon.
Creating a Class :
class Person:
pass # An empty block
We create a new class using the class statement followed by the name of the class. This follows an indented block of statements which form the body of the class. In this case, we have an empty block which is indicated using the pass statement.
Using Object Methds :
class Person:
def sayHi(self):
print 'Hello world'
The __init__ method :
The method is useful to do any initialization you want to do with your object. Note that The __init__() method can accept parameters, but does not return anything. It sets the internal state of the object.
class Person:
def __init__(self, name):
self.name = name
def sayHi(self):
print 'Hello, my name is', self.name
we define the __init__ method as taking a parameter name (along with the usual self). Here,we just create a new field also called name. Notice these are two different variables even though they have the same name. The dotted notation allows us to differentiate between them.
Most importantly, notice that we do not explicitly call the __init__ method but pass the arguments in the parentheses following the class name when creating a new instance of the class. This is the special significance of this method.
Built-In Class Attributes:
Every Python class keeps following built-in attributes and they can be accessed using dot operator like any other attribute:
__dict__ : Dictionary containing the class's namespace.
__doc__ : Class documentation string or None if undefined.
__name__: Class name.
__module__: Module name in which the class is defined. This attribute is "__main__" in interactive mode.
__bases__ : A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list.
Before move to advance, let's Overview of 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. Class variables aren't used as frequently as instance variables are.
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 (arguments) involved.
Instance variable: A variable that is defined inside a method and belongs only to the current instance of a class.
Inheritance : The transfer of the characteristics of a class to other classes that are derived from it.
Instance: An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
Instantiation : The creation of an instance of a class.
Method : A special kind of function that is defined in a class definition.
Object : A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.
Operator overloading: The assignment of more than one function to a particular operator.
Python is fully object-oriented: you can define your own classes, inherit from your own or built in classes, and instantiate the classes you've defined.The self Class methods have only one specific difference from ordinary functions - they must have an extra first name that has to be added to the beginning of the parameter list, but you do do not give a value for this parameter when you call the method, Python will provide it. This particular variable refers to the object itself, and by convention, it is given the name self.Although, you can give any name for this parameter, it is strongly recommended that you use the name self - any other name is definitely frowned upon.
Creating a Class :
class Person:
pass # An empty block
We create a new class using the class statement followed by the name of the class. This follows an indented block of statements which form the body of the class. In this case, we have an empty block which is indicated using the pass statement.
Using Object Methds :
class Person:
def sayHi(self):
print 'Hello world'
The __init__ method :
The method is useful to do any initialization you want to do with your object. Note that The __init__() method can accept parameters, but does not return anything. It sets the internal state of the object.
class Person:
def __init__(self, name):
self.name = name
def sayHi(self):
print 'Hello, my name is', self.name
we define the __init__ method as taking a parameter name (along with the usual self). Here,we just create a new field also called name. Notice these are two different variables even though they have the same name. The dotted notation allows us to differentiate between them.
Most importantly, notice that we do not explicitly call the __init__ method but pass the arguments in the parentheses following the class name when creating a new instance of the class. This is the special significance of this method.
Built-In Class Attributes:
Every Python class keeps following built-in attributes and they can be accessed using dot operator like any other attribute:
__dict__ : Dictionary containing the class's namespace.
__doc__ : Class documentation string or None if undefined.
__name__: Class name.
__module__: Module name in which the class is defined. This attribute is "__main__" in interactive mode.
__bases__ : A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list.
This comment has been removed by a blog administrator.
ReplyDeleteThanks for sharing, your post very informative. Top 10 Ethical Hackers in World
ReplyDelete
ReplyDeleteGood site you have here.. It’s hard to find quality writing like yours nowadays. I seriously appreciate people like you! If you are gaming enthusiast and is looking for the best monitor recommendations, you can always visit us . We have made a list of some of the best monitors with the best connectivity options and apt for programming and coding and graphic designing.
Nice Post...
ReplyDeleteI'm having very interesting information regarding Hire a Professional Hacker
Hire a hacker | Professional Email & Password Hacker Online | Grade change form
ReplyDeleteIf you want to hire a hacker or hire a professional email and password hacker online, then feel free to contact our experts at Anonymoushack.co. We are defining hacker for hire and solving your most complex problems very fast.
Website:- hackers near me
I believe this information will be very useful to someone out there because someone might still be in the same situation as me. I have been looking for a way to spy on my husband’s phone for quite some time but sadly most of the information available has not been useful. Tried some apps and software and none worked. I found this page some days ago but didn’t take it seriously. because I saw different comments and I got confused and I don't know who is real or not. So I summon the courage to contact a Wizard here his name wizardcyprushacker I send an email to him on {wizardcyprushacker@gmail.com} for help and they came through. I now have access to my husband’s iPhone and I found sufficient proof that he is seeing different women. Kindly reach out to him right now for a good job Email: {wizardcyprushacker@gmail.com} WhatsApp :+1 (424) 209-7204
ReplyDeleteUSA Fullz Database Bulk Quantity Available
ReplyDeleteComplete info with SSN DOB DL Employee Details
High Credit Scores Fullz USA
Credit Cards & DUMPS (TRACK 101 & 202)
752-822-040 I-C-Q
+92-317-272-1122 Whats-app
@killhacks Tele-Gram
Complete Tutorial Guides with Ebooks
All Tools regarding hac-king Services, Sp-am-ming Services
Card-ing Complete Course with free CC Samples
SHELLS/C-Panels,
WEB MAILERS
Spoofing
KE-YLOG-GERS
RA-TS for Hac-ks
LiNUX with TerMux
DA-RK W-E-B Guide with Course
Contact:
752-822-040 I-C-Q
@killhacks Tel-eGram
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHave you ever wanted to change grades and you had to contact many hackers to render this service but cannot guarantee a safe exploit for your school systems? I’ll urge you to contact Wizard James today because when it comes to network exploits, he is a Master in this. All you need to do is to purchase the hacking material and tools to penetrate each system. I am the happiest guy alive right now since I constantly rely on him for my grade change. Do reach out to him for help through wizardjamesrecovery @ usa . com. If you need a hacker for any form of hacking, Facebook, Gmail, yahoo mail, and grade change, Wizard James is your hacker.
ReplyDelete