Operator
Operators are used to perform mathematical operations on the values of two or more variables.
In the last article, we learn about the basic arithmetics.
More about arithmetic operators
There are %
, **
, and //
operators that are used to perform modulo, exponentiation, and integer division.
Modulo is the remainder of a division, exponentiation means raising a number to a power, and integer division is the division of two numbers without a remainder.
5 % 2
5 ** 2
5 // 2
Assignment Operators
Assignment operators are used to perform operations and assign that value to a variable.
x = 5
x += 2
The code above adds 2 to the variable and assigns the result to x.
x = 5
x = x + 2
The code above does the exact ame thing but is more repetitive.
There are assignment operators of every arithmetic operators -=
, _=
, /=
, **=
, %=
, //=
.
Comparison Operators
Comparison Operators compare two values and return a boolean value.
5 > 2
5 < 2
5 == 2
5 != 2
5 >= 2
5 <= 2
Note that they return boolean values.
==
returns whether two values are the same while !=
returns whether two values are different.
Logical Operators
Logical operators are used to combine boolean values.
True and True
True and False
False and True
False and False
True or True
True or False
False or True
False or False