LAB PRACTICE
Python Operator
COMMAND NAME EXAMPLE OUTPUT
+ Addition 4+5 9
- Subtraction 8-5 3
* Multiplication 4*5 20
/ Division 19/3 6
% Remainder 19%3 5
** Exponent 2**4 16
1. To print a statement
>>> print "Hello, World!"
2. To add two number
>>> 1 + 1
2
>>> 20+80
100
>>> 18294+449566
467860
3. To subtract two numbers
>>> 6-5
1
4. To multiply two numbers
>>> 2*5
10
>>> 5**2
25
5. Division
>>> 21/3
7
>>> 23/3
7
(division, 2nd time ignoring remainder/decimals,
>>> 23.0/3.0
7.6666...
3rd time including decimals)
6. To find the remainder from division using modulus operator
>>> 23%3
2
>>> 49%10
9
7. ORDER OF OPERATION
1. parentheses ()
2. exponents **
3. multiplication *, division \, and remainder %
4. addition + and subtraction -
>>> 1 + 2 * 3
7
>>> (1 + 2) * 3
9
8. USING PARENTHESIS
>>> 4 - 40 - 3
-39
>>> 4 - (40 - 3)
-33
9. COMMENTS EXAMPLES
>>> print "food is very nice" #eat me
food is very nice
>>># print "food is very nice"
(nothing happens, because the code was after a comment)
>>> print "food is very nice" eat me
(you will get a error message, because you didn't put your comment after a hash)
>>> #I am a comment. Fear my wrath!
>>>
NOTE: IMPLEMENT IN THE SYSTEM & TAKE DOWN IN THE NOTEBOOK