OOPs: ===== Object Oriented Programming System Programming Language Classified into three types: 1) Structured Programming Languages: C, C++, Python 2) Object Based : can implement anything with class and object only ex: VB Script 3) Object Oriented: C++, Java, Python etc. OOP Concept: Features: 1) Class 2) Object 3) Methods 4) Constructors 5) Destructors 6) Encapsulation 7) Polymorphism 8) Inheritance 9) Overloading 10) Overriding 11) Abstraction etc. Class: ====== Collection of Attributes and Behaviors is called as a class Attribute ==> data in the class Behavior ==> Method of implementation in a class class ==> Blueprint class definition does not require any memory How to define the class: ======================== Keyword: class Syntax: class name-of-the-class: class body which includes: data/attributes methods Object: ====== ==> Physical entity use to access the data (attributes or methods) from the class. ==> an object can reserve with a memory. Syntax: object-name/identifier = class-name() Accessing of an members of the class: ===================================== Syntax: object-name.member-name # Class Definition class myFirstClass: # attributes a = 100 b = 123.456 c = True d = 123-234j e = "OOPs" # a,b,c,d,e ==> Members of the class obj1 = myFirstClass() print(obj1.a) print(obj1.b) print(obj1.c) print(obj1.d) print(obj1.e) # print(a) ==================================== # Class with Collection members class myCollectionClass: al = [1,2,3,4,5] at = (1,3,5,7,9) ats = "Python" ase = {10,20,30,40,50} ad = {'a' : 100,'b' : 200,'c' : 300} object = myCollectionClass() print(object.al) print(object.at) print(object.ats) print(object.ase) print(object.ad) ====================================== Creation of More than one object for a class: ============================================= # Class with Collection members class myCollectionClass: al = [1,2,3,4,5] at = (1,3,5,7,9) ats = "Python" ase = {10,20,30,40,50} ad = {'a' : 100,'b' : 200,'c' : 300} object = myCollectionClass() obj = myCollectionClass() # obj1,obj2 = myCollectionClass() obj1 = myCollectionClass() obj2 = obj1 print(object.al) print(object.at) print(object.ats) print(object.ase) print(object.ad) print(obj.ats) print(obj1.al) print(obj2.at) ================================= Methods: ======== like functions: we need "def" keyword to define the method. Syntax: def method-name(self, parameters): method body with any implementation Like the functions, the methods also be invoked by using method class. Syntax for method call: method-name(values for the parameters) ==> Function can always define outside the class only. ==> if the function definition inside the class, we can call that definition as "method definition". ==> Method is a member of the class Syntax to access the method of the class: object-name.method-name(values for parameters) ==> to access/call the function, the object is not required. ==> method definition always require the self keyword as parameter. But the value for "self" is not required. Syntax: def method-name(self): method definition # Class with methods def function(): print("Hello All.") class methodClass: def met1(self): print("Hello, Good Morning.") def met2(self,name): print("Hello",name,"Good Afternoon.") def met3(self,name): return ("Hello {}, Good Evening.".format(name)) mo = methodClass() mo1 = methodClass() mo2 = methodClass() # mo.met1('xyz') mo.met1() mo1.met2("Anil") print(mo2.met3("Krishna")) Message = mo1.met3("Ravi") print(Message) # mo.function() function()