An operator is a particular symbol which is used on some values and produces an output as a result. An operator works on operands. Operands are numeric literals or variables which hold some values. Operators can be unary, binary or ternary. An operator which requires a single operand known as a unary operator, which require two operands known as a binary operator and which require three operands is called ternary operator
Example:
- # Unary Operator
- A = 12
- B = -(A)
- print (B)
- # Binary Operator
- A = 12
- B = 13
- print (A + B)
- print (B * A)
- #Ternary Operator
- A = 12
- B = 13
- min = A if A < B else B
- print(min)
Output:
# Unary Operator -12 # Binary Operator 25 156 # Ternary Operator 12