× Python Introduction What is Python Python Features Python History Python Applications Python Install Python Path Python Example Execute Python Keywords Constant Variable Statements & Comments Python I/O and Import Operators UnaryBinaryTernary Unary Operators Unary Minus Binary Operators Arithmetic Operators Assignment Operators Relational Operators Logicaloperators Bitwise Operator Ternary Operators Control Statements in Python conditonal Statements IF if else Else If Nested if Switch For loop Nested For Loop While Loop Nested while Loop Unconditonal Statemets Continue Break Pass FUNCTIONS Python Function Function Argument Python Recursion Anonymous Function Python Modules NATIVE DATATYPES Python List Python Numbers Python Tuple Python String Python Set Python Dictionary OOPS PRINCIPALS Encapsulation Class Variable Method Object Or Instance CreationMethod Calling OOPS Syntax And Explanation DATA ABSTRACTION Constructor Inheritance 1.Single or simple Inheritance 2.Multilevel Inheritance 3.Hierarchical Inheritance 4.Multiple Inheritance 5.Hybrid Inheritance Operator Overloading File Operation Python Directory Python Exception Python - Multithreading Python - Database Access Python - CGI Python - Reg Exp Python - Date Python - XML Processing Python - GUI
  • iconpython Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM

Python OOPS Syntax


import Statements;
..
..

class ClassName1:
    ....
    ....

class ClassName2:
    ....
    ....

class ClassName3:
    ....
    ....

class ClassName4:
    ....
    ...

...
...

if __name__=="__main__":

    c1=ClassName1()
    ...
    ...
    ...

    c1.method()
    ..
    ..  

Key Points

  • Python OOPS Syntax
  • Image
    1 Class 4 Methods Using OOPS Syntax
    OOPS Program
    class Demo:
        def add(self):
            x=10
            y=20
            z=x+y
            print(z)
        def sub(self):
            x=10
            y=20
            z=x-y
            print(z)
    
        def mul(self):
            x=10
            y=20
            z=x*y
            print(z)
        def div(self):
            x=10
            y=20
            z=x/y
            print(z)
    
    if __name__=="__main__":
        d=Demo()
        d.add()
        d.sub()
        d.mul()
        d.div()
    
                                    

    Output:
    4 Classs each class 1 Method Using OOPS Syntax
                              
                          

    Output:
    class addition:
        def add(self):
            x=10
            y=20
            z=x+y
            print(z)
    class substraction:
        def sub(self):
            x=10
            y=20
            z=x-y
            print(z)
    class multiplication:
        def mul(self):
            x=10
            y=20
            z=x*y
            print(z)
    class division:
        def div(self):
            x=10
            y=20
            z=x/y
            print(z)
    
    if __name__=="__main__":
        a=addition()
        s=substraction()
        m=multiplication()
        d=division()
        a.add()
        s.sub()
        d.div()
        m.mul()