Problem Solving Using Python: Assistant Professor, Dept. of CSE, SJCET Palai
Problem Solving Using Python: Assistant Professor, Dept. of CSE, SJCET Palai
Prof. Sarju S
Assistant Professor, Dept. of CSE, SJCET Palai
Page 2
Operators and operands
► Operators are special symbols that represent computations like addition and
multiplication. The values the operator uses are called operands.
► The following are all legal Python expressions
► 20+32 hour-1 hour*60+minute minute/60 5**2 (5+9)*(15-7)
► The symbols +, -, and /, and the use of parenthesis for grouping, mean in
Python what they mean in mathematics.
► The asterisk (*) is the symbol for multiplication, and ** is the symbol for
exponentiation
► Python follows the same precedence rules for its mathematical operators that
mathematics does.
► Operators with the same precedence are evaluated from left to right.
Page 9
The modulus operator
► The modulus operator works on integers (and integer expressions) and yields
the remainder when the first operand is divided by the second.
► In Python, the modulus operator is a percent sign (%).
>>> quotient = 7 / 3
>>> print quotient
2
>>> remainder = 7 % 3
>>> print remainder
1
So 7 divided by 3 is 2 with 1 left over.
Thank You
Prof. Sarju S
Department of Computer Science and Engineering
St. Joseph’s College of Engineering and Technology, Palai
https://www.linkedin.com/in/sarju-s/
Email: [email protected]
Page 14