Operators: Operators are symbols or keywords in a programming language that perform operations on operands (values or variables). They are used to manipulate data and perform calculations in expressions.
Examples of unary operators:
- Unary minus/negation: – (e.g., -x)
- Unary plus: + (e.g., +x)
- Increment: ++ (e.g., x++) [Note: Python does not have a built-in increment operator, but it can be achieved using other constructs.]
Examples of binary operators:
- Arithmetic operators:
- Addition: + (e.g., x + y)
- Subtraction: – (e.g., x – y)
- Multiplication: * (e.g., x * y)
- Division: / (e.g., x / y)
- Modulo: % (e.g., x % y)
- Exponentiation: ** (e.g., x ** y)
- Floor division: // (e.g., x // y)
- Comparison operators:
- Equal to: == (e.g., x == y)
- Not equal to: != (e.g., x != y)
- Greater than: > (e.g., x > y)
- Less than: < (e.g., x < y)
- Greater than or equal to: >= (e.g., x >= y)
- Less than or equal to: <= (e.g., x <= y)