What is an operator in Python?

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:

  1. # Unary Operator  
  2. A = 12  
  3. B = -(A)  
  4. print (B)  
  5. # Binary Operator  
  6. A = 12  
  7. B = 13  
  8. print (A + B)  
  9. print (B * A)  
  10. #Ternary Operator  
  11. A = 12  
  12. B = 13  
  13. min = A if A < B else B  
  14.     
  15. print(min)  

Output:

# Unary Operator
-12
# Binary Operator
25
156
# Ternary Operator
12