7 Python Arithmetic Operators with Examples [Tutorial]


List of Arithmetic Operations in Python:

  1. Addition: +
  2. Subtraction: -
  3. Multiplication: *
  4. Division: /
  5. Floor Division: //
  6. Modulus: %
  7. Exponential: **

Python Arithmetic Operators Examples

  1. Addition: +

    Example:
    # Python: Arithmetic Operator: Addition (+) Example
    
    number1 = 10;
    number2 = 20;
    
    #Addition
    sum = number1 + number2;
    
    print(sum);
    Output:

    30

  2. Subtraction: -

    Example:
    # Python: Arithmetic Operator: Subtraction (-) Example
    
    number1 = 30;
    number2 = 20;
    
    #Subtraction
    difference = number1 - number2;
    
    print(difference);
    Output:

    10

  3. Multiplication: *

    Example:
    # Python: Arithmetic Operator: Multiplication (*) Example
    
    number1 = 10;
    number2 = 20;
    
    #Multiplication
    mutiplicationResult = number1 * number2;
    
    print(mutiplicationResult);
    Output:

    200

  4. Division: /

    Example:
    # Python: Arithmetic Operator: Division (/) Example
    
    number1 = 20;
    number2 = 10;
    
    #Division
    divisionResult = number1 / number2;
    
    print(divisionResult);
    Output:

    10

  5. Floor Division: //

    # Python: Arithmetic Operator: Floor Division (//) Example
    
    number1 = 21;
    number2 = 4;
    
    #Floor Division
    #Using Floor Division you get the rounded nearest whole number as the result.
    floorDivisionResult = number1 / number2;
    
    print(floorDivisionResult);
    Output:

    5

  6. Modulus: %

    # Python: Arithmetic Operator: Modulus (%) Example
    
    number1 = 10;
    number2 = 2;
    
    #Modulus
    modulusResult = number1 % number2;
    
    print(modulusResult);
    Output:

    0

  7. Exponentiation: **

    # Python: Arithmetic Operator: Exponentiation (**) Example
    
    number1 = 10;
    number2 = 5;
    
    #Modulus
    exponentialResult = number1 ** number2;
    
    print(exponentialResult);
    Output:

    100000

Python Programming Addition Operator Example
Python Programming Division Operator Example
Python Programming Exponential Operator Example
Python Programming Floor Division Operator Example
Python Programming Modulus Operator Example
Python Programming Multiplication Operator Example
Python Programming Subtraction Operator Example
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.