You can learn about Operators in Python Programs with Outputs helped you to understand the language better.
Python Programming – Operators
Operators
An operator is a particular symbol that is used on some values and produces an output as a result. In other words, the operator in Python specifies an operation to be performed on the variables that yield a resultant value. The operator works on operands. An operand is an entity on which the operator acts. For example, in the expression: a + b
- Python Programming – Expressions
- Python Programming – Variable
- Python Programming – Arithmetic Operators
the sign + is an operator which specifies the operation of addition on the two operands a and b. Operators can be unary, binary or ternary. The operator which requires a single operand is known as a unary operator; the operator which requires two operands is known as a binary operator, and which requires three operands is called the ternary operator. For example,
-X # here – is a unary operator
7+2=9# here + is a binary operator
# Assign minimum value using ternary operator
x, y = 5, 7
minimum = x if x < y else y
print(minimum)
Two operators, + and -, can be used as unary operators. The unary operator has only one operand. It expects a single numeric expression (literal number, variable, or more complicated numeric expression within parentheses) immediately to its right; it computes the additive inverse of its operand.
A binary operator is an operator that takes two arguments (for example, + or /). A unary operator operates on a single value. (For example, -)
Python language operators are classified into the following types. These are:
- Arithmetic Operators
- Relational (Conditional) Operators
- Logical / Boolean Operators
- Assignment Operators
- Bitwise Operators
- Membership Operators
- Identity Operators