Operators in Python
Operators are special symbols that
perform operations on operands (values or variables).
- Arithmetic Operators:
- + (addition)
- - (subtraction)
- * (multiplication)
- / (division)
- // (floor division)
- % (modulo - gives the remainder)
- ** (exponentiation)
- Relational Operators:
- > (greater than)
- < (less than)
- >= (greater than or equal to)
- <= (less than or equal to)
- == (equal to)
- != (not equal to)
- Logical Operators: 1
- and (logical AND)
- or (logical OR)
- not (logical NOT)
- Assignment Operators:
- = (simple assignment)
- += (add and assign)
- -= (subtract and assign)
- *= (multiply and assign)
- /= (divide and assign)
- //= (floor divide and assign)
- %= (modulo and assign)
- **= (exponentiate and assign)
- Augmented Assignment Operators:
- Combine an arithmetic operator with the assignment
operator.
- Example: x += 5 is
equivalent to x
= x + 5
- Identity Operators:
- is: Checks if two objects are the same object in memory.
- is not: Checks if two objects are not the same object in
memory.
- Membership Operators:
- in: Checks if a value is present in a sequence (string,
list, tuple).
- not in: Checks if a value is not present in a sequence.
No comments:
Post a Comment