Object Oriented Programming =========================== High level programming language control statements functions etc. if, else, elif, while, for, def etc. C, C++, Python, Java, C# etc. Functional nature C ==> printf(), scanf(), putchar(), getchar(), fprintf() etc. Python ==> len(), id(), print() etc. Object Oriented OOPs Concepts ==> Class, Object, Methods, Encapsulation etc. C++, Python Scripting Nature Perl, Shell Script, Python classified into three types: ============================ Structured ==> cannot support any of OOPs Concepts Ex: C (Functions, Pointers, Structures, Unions etc.) Python Object Based ==> can support only: class and object Ex: VB Script Object Oriented ==> can support all the OOPs concepts Ex: C++, Python, Java, C# etc. OOPs (Object Oriented Programming System) Features: Class, Object, Methods, Constructors, Destructors, Encapsulation, Polymorphism, Inheritance, Data Abstraction etc. Why OOPs? ========= 1) Simpler 2) Reusability 3) Override data fun1(): a+b fun1(): a*b 4) Security Encapsulation, Data Abstraction etc. =========================================== Class in Python: ================ ==> Collection of attributes (data) and Behavior (Methods) is called as "Class". ==> Blueprint of object. ==> Logical Entity. ==> No memory is required. Person: name gender age dob designation behaviors: study() work() person-1: name : Amisha gender : female age : 24 Software Engineer work(): working at abc Pvt Ltd study(): she can study 2 hours per a day. person-2: name : Hyma gender : Female age : 25 Software Engineer work() : at xyz study() 3 hrs/day Object: ======= An instance of the class. using Object, we can access all the attributes and methods of the class. Physical Entity. Memory is required. Creation of the class: ====================== keyword: class Syntax: ======= class any-identifier(class-name): attributes/data methods creation of an object: ===================== object-name (identifier) = class-name() Accessing of Attributes of the class using an object: ===================================================== object-name.member-name Note: ==== for one class, we can define any number of objects. =============================================== Changing of Attribute values using an object: ============================================= class Person: name = "Amisha" gender = "female" age = 24 # members of the class. user1 = Person() # Accessing of class data/attributes # print(user1.name) name_user = user1.name print(name_user) print(user1.gender) print(user1.age) user2 = Person() user2.name = "Hyma" user2.age = 25 print(user2.name) print(user2.gender) print(user2.age) user3 = Person user3.name = "Gazala" user3.age = 22 print(user3.name) print(user3.gender) print(user3.age) ============================================ Class with methods: =================== method: ======= like the function, method is also the named block which it can use to define the block of code for the specific task. keyword: def Method Vs Function: =================== function ==> always define in outside the class. method ==> always define in inside the class. ==================== Syntax: ======= class class-name: def method-name(self,par1, par2, par3,...): method implementation return here: self ==> parameter without value describing that the method is belonging to the specific class. Accessing of methods of class using an object: ============================================= object-name.method-name(val1, val2, val2,..) class Person(): def work(self): return "I am working at ABC Corporation Limited." def study(self): return "I am Studying for 5 hours a day after my work." us1 = Person() print(us1.work()) print(us1.study()) Note: ==== to use the attribute of class inside the method of the same class: self.attribute-name class Student: name = input("Enter the name:") cls = input("Enter the class section:") gender = input("Enter gender:") roll = input("Enter roll:") def studentInfo(self): print("The Name of the student = ",self.name) print("The Section of Student = ",self.cls) print("The Gender = ",self.gender) print("The Roll of the student = ",self.roll) stu1 = Student() stu2 = Student() # stu1.studentInfo() stu2.studentInfo() ========================== class Calculator: a = 100 b = 200 def addition(self): res1 = self.a + self.b print("The Sum = ",res1) def muliplication(self): res2 = self.a * self.b print("The Multiplication = ",res2) calci = Calculator() print("Attributes of class are = ") print(calci.a) print(calci.b) # calling methods of the class calci.addition() calci.muliplication()