Skip to main content

Tutorial 4:Arithmetic Operators in Pythons

Revision
In previous tutorial, we've known that 5 is an integer and "5" is string.  and "5" are in different types. How about 2+3 and "2+3"

Review Exercise 1 : Write the following input code in your Python program and run the program. What is the output?
>>>print(2+3)
What is the type of 2+3?

Review Exercise 1 : Write the following input code in your Python program and run the program. What is the output?
>>>print("2+3")
What is the type of "2+3"?

The output in Review Exercise 1 is 5.
The output in Review Exercise 2 is 2+3.
This is because and are intergers. Python operates adding and . In this case, and are called operands and + is the operator.

The type of 2+3 is integer while "2+3" is string. Different 

 OperatorNameExampleOutput
 +addition
x+y the value of x+y
 -subtractionx-ythe value of x-y
 *multiplicationx*y the value of x times y
 /division x/y the result of x divides y
 %modulusx%y the remainder when x divides y 
 **Exponentiation x**y the value of xy 
 //floor division x//y the greatest integer less than the result of x divides y 

Comments