top of page

Python Operators

INTRODUCTION:


Python uses operators to compare and perform mathematical functions. They are used to perform specific functions that are shown using symbols (For example: *, /, &) Python has seven types of variables: arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. They are used to perform operations on operands. Operands are the values that are being operated upon. For example:


Operands - Operators


2 + 8 * 7


ARITHMETIC OPERATORS:


There are 7 arithmetic operators in Python. They are:


  • 1: ADDITION +


The addition operator is used to add operands. It is the same symbol that we use in mathematics. For example:


12 + 8


  • 2: SUBTRACTION -


The subtraction operator is used to subtract operands. Just like the addition operator, it is the same symbol we use in mathematics. For example:


z - x


  • 3: MULTIPLICATION *


The multiplication operator is slightly different from addition and subtraction because it’s symbol is not the same as what is used in mathematics. It is used to multiply values. For example:

5 * 13


  • 4: DIVISION /


The division operator is used to divide operands. For example:


20 / 5


  • 5: MODULUS “ %


The modulus operator is used to find the remainder of a division equation. It is not the quotient but the remainder. For example:


5 / 2 = 2.5


5 % 2 = 1


  • 6: EXPONENTIAL **


The exponent operator is used to add an exponent or index to a number. For example:


6 ** 4 = 1296


  • 7: FLOOR DIVISION//


The floor division operator is used to round the result down to the lowest possible whole number after dividing it. However, if the number is negative, the floor division operator will increase the digit along with the negative sign. For example:


15 // 2


ASSIGNMENT OPERATORS:


In Python, there are 13 assignment operators. They are used to assign values and make arithmetic equations simpler. The 13 assignment operators are:


  • 1: EQUAL TO=


The equal to operator is used to assign a value. It is extremely similar to the “ == ” operator but the “ == ” operator is used to compare two values while the “ = ” operator is used to assign values to a variable. For example:


x = 37


  • 2: ADDITION / EQUAL TO+ =


The addition/equal to operator is used to signify that the variable is assigned to the value of itself plus the number following the “+ = ” sign. For example:


‘ x + = 3 ’ is the same as ‘ x = x + 3 ’


  • 3: SUBTRACTION / EQUAL TO- =

The subtraction/equal to operator is used to signify that the variable is assigned to the value of itself minus the number following the “ - = ” sign. For example:


‘ x - = 3 ’ is the same as ‘ x = x - 3 ’


  • 2: MULTIPLICATION / EQUAL TO+ =


The multiplication/equal to operator is used to signify that the variable is assigned to the value of itself times the number following the “ * = ” sign. For example:


‘ x * = 3 ’ is the same as ‘ x = x * 3 ’


  • 3: DIVISION / EQUAL TO- =


The division/equal to operator is used to signify that the variable is assigned to the value of itself divided by the number following the “ / = ” sign. For example:


‘ x / = 3 ’ is the same as ‘ x = x / 3 ’


  • 4: MODULUS / EQUAL TO% =


The modulus/equal to operator is used to signify that the variable is assigned to the value of the remainder of the division equation between the two numbers. I know, it looks a bit complicated but the example will explain it all:


‘ x % = 3’ is the same as ‘ x = x % 3 ’


  • 5: FLOOR DIVISION / EQUAL TO// =


The floor division/equal to operator is used to signify that the variable is assigned to the value of the division equation between the two numbers rounded to its lowest number. However, if this operator is used for negative numbers, then it is rounded to a higher digit along with a negative sign. It is the same as the floor division operator. For example:


‘ x // = 73 ’ is the same as ‘ x = x // 73 ’


  • 6: EXPONENTIAL / EQUAL TO** =


The exponential/equal to operator is used to signify that the variable is assigned to the value of itself to the power of the number following it. For example:


‘ x ** = 5’ is the same as ‘ x = x ** 5 ’


  • 7: AND / EQUAL TO& =


The and/equal to operator is used to signify that


12 views0 comments

Recent Posts

See All

Java Notes on Basic Functions

From the AP Computer Science A curriculum, read this tutorial to learn about basic functions in Java.

bottom of page