DEV Community

still-purrfect
still-purrfect

Posted on

Operators in Programming: Making Your Code Do the Math

So far, we’ve learned how to store and organize data using variables and different data structures. But storing data is only part of programming.
At some point, we need to actually work with that data.
That’s where operators come in.
Operators are symbols that allow us to perform actions on values. They help the program calculate, compare, and make decisions.
Think of them as the basic tools that make your code functional.
For example:

x = 10
y = 5

print(x + y)
Enter fullscreen mode Exit fullscreen mode

Here, the + is an operator. It tells the program to add the two values together.

🔹 Types of Operators

1. Arithmetic Operators ➕➖✖️➗

These are used for basic mathematical operations:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • % modulus (remainder)

Example:

print(10 % 3)
Enter fullscreen mode Exit fullscreen mode

This returns the remainder after division.

2. Comparison Operators ⚖️

These are used to compare values and return True or False:

  • == equal to
  • != not equal to
  • > greater than
  • < less than
  • >= greater or equal
  • <= less or equal

Example:

x = 10
print(x > 5)
Enter fullscreen mode Exit fullscreen mode

This returns True because 10 is greater than 5.

3. Logical Operators 🧠

These help combine conditions:

  • and
  • or
  • not

Example:

x = 10

print(x > 5 and x < 20)
Enter fullscreen mode Exit fullscreen mode

This checks if both conditions are true.

💡 Why Operators Matter

Operators are what make your program active instead of just storing information.
Without them, your code just holds data.
With them, your program can calculate, compare, and respond to conditions.
That’s what makes it useful.

🌱 Challenge

Create two variables:

  • One for your age
  • One for your friend’s age Then:
  • Add them together
  • Check who is older
  • Print the results Keep it simple and focus on understanding how the operators work.

In the next article, we’ll use these operators to make decisions in code using if statements.

Top comments (0)