Lesson03 Operators
Lesson03 Operators
Operators are the constructs, which can manipulate the value of operands
Types of Operators
a) Arithmetic Operators
b) Comparison (Relational) Operators
c) Assignment Operators
d) Logical Operators
e) Bitwise Operators
f) Membership Operators
g) Identity Operators
Arithmetic Operators
Compare values on either side of the operator and decide if the relation among
them is either true or false. These are equal to (==), not equal to (!=),
greater than (>), less than (<), greater than or equal to (>=), less than or
equal to ( <=)
Assignment Operators
A. Irungu
*= Multiply AND It multiplies right c *= a is equivalent to c = c * a
operand with the left
operand and assign the
result to left operand
/= Divide AND It divides left operand c /= a is equivalent to c = c / a
with the right operand
and assign the result to
left operand
%= Modulus AND It takes modulus using c %= a is equivalent to c = c % a
two operands and assign
the result to left operand
**= Exponent AND Performs exponential c**=a is equivalent to c = c** a
(power) calculation on
operators and assign
value to the left operand
//= Floor Division It performs floor division c //= a is equivalent to c = c // a
on operators and assign
value to the left operand
Bitwise Operators
a = 0011 1100
b = 0000 1101
a&b = 0000 1100 (AND)
a|b = 0011 1101 (OR)
a^b = 0011 0001 (XOR)
~a = 1100 0011 (unary operation Binary One’s complement)
Logical Operators
Logical Operations evaluate to either true or false. The operators used are
and, or, and not
Membership Operators
Identity Operators
Operator precedence
A. Irungu
Exponentiation (raise to the power)
**
complement, unary plus and minus
~, +@, -@
Multiply, divide, modulo and floor division
*, /, %, //
Addition and subtraction
+, -
Right and left bitwise shift
>>, <<
Bitwise 'AND'
&
Bitwise exclusive `OR' and regular `OR'
^, |
Comparison operators
<=, <, >, >=
Equality operators
<>, ==, !=
Assignment operators
= ,%=, /=, //=, -
=, +=, *=,**=
Identity operators
is, is not
Membership operators
in, not in
Logical operators
not, or, and
A. Irungu