Class XI Python Arithmetic operators 2024-2025

 


Python arithmetic operators are used to perform basic mathematical operations on numbers. Here are the main arithmetic operators in Python:

  1. Addition (+): Adds two operands.
  2. Subtraction (-): Subtracts the second operand from the first.
  3. Multiplication (*): Multiplies two operands.
  4. Division (/): Divides the first operand by the second. The result is a float.
  5. Modulus (%): Returns the remainder of the division of the first operand by the second.
  6. Exponentiation (**): Raises the first operand to the power of the second.
  7. Floor Division (//): Divides the first operand by the second and rounds down to the nearest integer.

Examples:

# Variables for demonstration a = 10 b = 3 # Addition addition = a + b # 10 + 3 = 13 # Subtraction subtraction = a - b # 10 - 3 = 7 # Multiplication multiplication = a * b # 10 * 3 = 30 # Division division = a / b # 10 / 3 = 3.333... # Modulus modulus = a % b # 10 % 3 = 1 # Exponentiation exponentiation = a ** b # 10 ** 3 = 1000 # Floor Division floor_division = a // b # 10 // 3 = 3

These operators are fundamental to performing calculations and processing numerical data in Python. The result type (integer or float) may vary depending on the operation and the operands involved. For instance, the division operator / always returns a float, while the floor division operator // returns an integer if both operands are integers.

Post a Comment

0 Comments