Revision
In previous tutorial, we've known that 5 is an integer and "5" is string. 5 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 2 and 3 are intergers. Python operates adding 2 and 3 . In this case, 2 and 3 are called operands and + is the operator.
The type of 2+3 is integer while "2+3" is string. Different
Operator | Name | Example | Output |
+ | addition | x+y | the value of x+y |
- | subtraction | x-y | the value of x-y |
* | multiplication | x*y | the value of x times y |
/ | division | x/y | the result of x divides y |
% | modulus | x%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
Post a Comment