Standard Arithmetic Operators ( + - * / )
Standard arithmetic functions work as normal in Python. Take note that multiplication is achieved using an asterisk * .
a = 5 b = 3 result = a + b
result = a - b print(result) #The output will be 2.
result = a * b print(result) #The output will be 15.
a = 10 b = 2 result = a / b print(result) # The output will be 5.0.
Arithmetic operators are used to perform [[mathematical]] calculations.
{"cloze_text": "Arithmetic operators are used to perform [[mathematical]] calculations."}
The arithmetic operator [[*]] is used to perform multiplication.
{"cloze_text": "The arithmetic operator [[*]] is used to perform multiplication."}
In Python, what is the result of the expression 20 - 10?
{"answers": {"A": "10", "B": "None", "C": "30", "D": "20"}, "question_text": "In Python, what is the result of the expression 20 - 10?", "correct_answer": "A"}
Modulo (%)
The modulo operator is used to find the remainder of a division. For example:
a = 15 b = 4 result = a % b print(result) #The output will be 3.
What is the remainder when 7 is divided by 2?
{"answers": {"A": "3", "B": "2", "C": "1", "D": "0"}, "question_text": "What is the remainder when 7 is divided by 2?", "correct_answer": "C"}
Floor division
Floor division (also known as integer division) is performed using the double forward slash operator //.
It divides one number by another and returns the quotient rounded down to the nearest whole number.
x = 10
y = 3
result = x // y # Floor division of 10 by 3
print(result) # Output: 3
What is the result of 10 // 3?
{"answers": {"A": "3", "B": "2", "C": "3.33", "D": "2.5"}, "question_text": "What is the result of 10 // 3?", "correct_answer": "A"}
Exponentiation (**)
The exponentiation operator is used to raise a number to a power.
Example:
a = 2
b = 3
result = a ** b
print(result) #The output will be 8.
In Python, what is the result of 2 ** 4?
{"answers": {"A": "6", "B": "0.5", "C": "16", "D": "8"}, "question_text": "In Python, what is the result of 2 ** 4?", "correct_answer": "C"}
Review: Fill in the Blanks
Standard arithmetic operators in Python include addition, subtraction, multiplication, and division, where multiplication is indicated by the symbol. For instance, if you assign the value 5 to variable and 3 to variable , the expression `a + b` will calculate the sum.
The modulo operator, represented by the symbol , is specifically used to find the from a division operation. For example, if you have 15 and 4 assigned to variables and , respectively, using `a % b` will give the remainder of the division.
Floor division, also known as , is performed using the double forward slash operator . This operation divides one number by another and yields the quotient rounded down to the nearest whole number, such as dividing 10 by 3 which results in an output of .
Exponentiation is performed using the double asterisk operator , which raises a number to a specific . For example, if you set a to 2 and b to 3, the expression `a ** b` calculates 2 raised to the third power, resulting in an output of .
The modulo operator, represented by the symbol , is specifically used to find the from a division operation. For example, if you have 15 and 4 assigned to variables and , respectively, using `a % b` will give the remainder of the division.
Floor division, also known as , is performed using the double forward slash operator . This operation divides one number by another and yields the quotient rounded down to the nearest whole number, such as dividing 10 by 3 which results in an output of .
Exponentiation is performed using the double asterisk operator , which raises a number to a specific . For example, if you set a to 2 and b to 3, the expression `a ** b` calculates 2 raised to the third power, resulting in an output of .
Click the keywords below to fill in the blanks:
A
**
8
A
Power
B
Remainder
Asterisk
Integer Division
B
3
%
//
â All blanks filled correctly! Great job!
Complete! Ready to test your knowledge?
Arithmetic Operators in Python
- Standard Arithmetic Operators ( + - * / )
- Modulo (%)
- Floor division
- Exponentiation (**)