operators :
~~~~~~~~~~~~~~~~~~
operator
operand
expression
the collection of operators and operands
is known as expression.
types of operators
. according to the no of operands
. unary
. binary
. ternary
. according to the operation
. arithmatic + - * / % ** //
. assignment =
. compaund assignment += -= *= /= %= **= //= &= |= ^= >>=
>>=
. relational < > >= <= == !=
. conditional ?:
. bitwise & | ^ >> << ~
. logical && || !
. special () [] .
extra operatos only supported by python
. membership in not in
. identity is is not
ARITHMATIC OPERATOR :
python does not support ++ and -- operator
c/c++/java c/c++/java/python c/c++/java/python
x ++ x = x + 1 x += 1
python added some new operators in arithmatic section
** exponential to find power
// floor div to find the lowe limit of div
in c cpp java
// comment line
in python
# comment line
while working with operators
there are two different protocal are aval,
. PRECEDENCE
if multiple operators aval in an expression
which operator will execute first
that will be decided by precedence.
precedence is used to decide the priority of operators.
. ASSOCIATIVITY
if multiple operators enjoy same precedence
then the order of evaluation
will be decided by associvity.
left to right
right to left
PRECEDENCE TABLE
~~~~~~~~~~~~~~~~~
1. () [] . L TO R
2. ** R TO L
3. ~ + - ( UNARY )
4. * / % // L TO R
5. + - ( BINARY ) L TO R
6. >> <<
7. &
8. ^
9. |
10. < > <= >=
11. == !=
12. = += -= *= /= %= **= //= &= |= ^= >>= <<=
13. is is not
14. in not in
15. not or and ( logical )