Operators

Learn about the three major types of operators used, including arithmetic, relational, and logical operators.

Operators

Previously, we discussed how a statement is made up of expressions and that expressions can be made up of operations or operands.

Let’s see an example of this. Here, we’ll create two variables and assign a value to each of them. Then, we’ll add the two values together and store the result in a new variable:

Press + to interact
number1 = 10
number2 = 15
result = number1 + number2
print result

On line 1, we create a variable called number1 and assigned the value 10 to it. We now know that this means several things:

  • The variable name is number1.
  • Because it’s assigned an integer, it must be of the integer type.
  • The = sign is an operator, taking whatever is on the right and assigning it to what we have on the left.
  • Somewhere in
...