Operators are symbols in Python that let you do things like math, compare values, or make decisions in your code.

They help you add numbers together, check if two values are equal, or even decide what code to run based on certain conditions.

Having learned how to create numbers in Python, let's start with the arithmetic operator.

Just like in math class, Python uses symbols to perform arithmetic operations.

These operations allow you to add, subtract, multiply, and more, directly within your code.

Arithmetic "operators," and they are essential tools for handling numbers in programming.

Addition (+)

The + operator adds two numbers together. It's the most straightforward arithmetic operation. Here's how you use it:


print(3 + 5)  # Outputs 8 
print(10 + 20)  # Outputs 30

Subtraction (-):

The - operator subtracts one number from another. It's used when you want to find the difference between two numbers.


print(10 - 5)  # Outputs 5 
print(20 - 3)  # Outputs 17

Multiplication (*)

This operator multiplies two numbers. Multiplication in JavaScript is efficient and follows standard arithmetic rules, scaling one number by another.


print(3 * 5)  # Outputs 15 
print(10 * 20)  # Outputs 200

Division (/)

Division divides one number by another. It's important to note that dividing by zero in JavaScript results in Infinity, or -Infinity if the number being divided is negative.


print(10 / 2)  # Outputs 5.0 
print(20 / 3)  # Outputs approximately 6.6667

Advance Operators

Modulus (%)

The modulus % operator returns the remainder of a division. It's particularly useful for determining whether a number is even or odd, or for finding the remainder when an item is divided into equal parts.


print(10 % 3)  # Outputs 1 because the remainder of 10 divided by 3 is 1
print(25 % 4)  # Outputs 1 because the remainder of 25 divided by 4 is 1
print(9 % 2)  # Outputs 1 because the remainder of 9 divided by 2 is 1 (odd number)

Integer Division (//)

The // operator divides one number by another, but it rounds down the result to the nearest whole number. This is useful when you need to divide something into equal parts without fractions, like distributing items equally.


print(20 // 3)  # Outputs 6 
print(9 // 2)  # Outputs 4

Exponentiation (**)

The operator raises one number to the power of another. This is used for exponential growth calculations, squaring numbers, or more complex mathematical modeling.


print(2 ** 3)  # Outputs 8 
print(3 ** 2)  # Outputs 9

These examples showcase basic usage of each arithmetic operator in Python.

Each operation manipulates numbers directly and outputs the result, which is helpful for understanding the immediate effects of these operations within code.

Using these operators effectively can aid in a wide variety of tasks, from simple calculations to more