0% found this document useful (0 votes)
7 views11 pages

7 - Arithmetic-Operators

The document explains various arithmetic operators in Python, including addition, subtraction, multiplication, division, exponentiation, modulus, and integer division. It emphasizes the importance of the order of operations (PEMDAS) and provides tips for determining even and odd numbers using the modulus operator. Additionally, it notes that there are more operators in Python that will be covered in future videos.

Uploaded by

linghao0521
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

7 - Arithmetic-Operators

The document explains various arithmetic operators in Python, including addition, subtraction, multiplication, division, exponentiation, modulus, and integer division. It emphasizes the importance of the order of operations (PEMDAS) and provides tips for determining even and odd numbers using the modulus operator. Additionally, it notes that there are more operators in Python that will be covered in future videos.

Uploaded by

linghao0521
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Arithmetic Operators

Recap

In the previous video, we wrote this piece of code, which prints out the sum
of 5 and 3.
The "+" in the code is called an arithmetic operator, and it is one of many
operators in python.
Arithmetic Operators
Operators

As you might've noticed, addition and subtraction are just like normal math operators.
Operators

For multiplication, we use the "*" operator which is called an asterisk, and for division,
we use the "/" operator, which is called a forward slash.
Operations Ordering
Note that the order of operations in python, is the same as in math.
Python follows a rule called PEMDAS, which you can know more about here if
you are not familiar with
Example:

Note that adding parentheses to the first code changed the value of the
mathematical operation, so always take care about your calculations.
Exponent Operator

In python, we use "**" operator to denote exponentiation (power) .


So when saying 3**2, this is equivalant to saying 3² which is equal to 9

Note:
** is different from ^, make sure not to get confused and use ^ instead of **
The ^ operator is called the caret operator, which is used to perform bitwise XOR.
This is something a little advanced for now, but if you want, you can read about
that here.
Modulus Operator

The % operator is used to get the remainder of the division operator

Pro Tip:
To determine whether a number is even or odd, you can get the modulo of two for
this number, if it is equal to one, then this number is odd, otherwise, it is even.
Have a look on the previous snippet of code.
Integer Division Operator

The // operator is used to get the integer floor division (aka integer division) of two
numbers. It rounds down the division result, and ignores the floating points.

Notice the different between the first example and the second one.
Integer Division Operator

The // operator is used to get the integer floor division (aka integer division) of two
numbers. It basically get the integer division and ignores the floating points.

Note that the // operator works with negative numbers as well.


But in this case, it rounds up the result, instead of rounding down.
Other operators
In this video, we discussed the arithmetic operations, however, these are not the only
operators in python, and there is still much more.

In the next videos, we will discuss more operators in python.

You might also like