Mathematical Operations

Understanding Mathematical Operations in Code

Mathematical operations are fundamental to programming, enabling us to perform calculations, manipulate data, and solve complex problems. Here’s a quick overview of how these operations work in code.

Basic Operations

  1. Addition (+): Combines values.
    result = 5 + 3  # result is 8
    
  2. Subtraction (-): Calculates the difference.
     result = 10 - 4  # result is 6
    
  3. Multiplication (*): Scales a value.
     result = 7 * 6  # result is 42
    
  4. Exponentiation (^): Raising a number to a power can be done using the ** operator.
     result = 2 ** 3  # result is 8
    
  5. Modulus (%): Finds the remainder of division.
     result = 10 % 3  # result is 1