 # Operators and operands in Python

## Operators and Operands in python, a brief description

We will briefly explain the Operators and operands in Python. Operators are special symbols in programming. They represent computations like addition, subtraction, division, and multiplication.
For example
>>> A = 10
>>> B = 10
>>> C = a+ b

Here a and b are operands. The values the operator is applied to are called operands.
The operators +, -, *, /, and ** are addition, subtraction, multiplication, division, and exponentiation respectively.

The division operator is changed from python 2 to python 3. In Python 3.x, the result of this division is a ﬂoating point result.
For example,
>>> minute = 59
>>> minute/60

Output: 0.9833333333333333

The division operator in Python 2.0 would divide two integers. It truncates the result to an integer as in the following example variable:

>>> minute = 59

>>> minute/60

Output: 0

To obtain the same answer in Python 3.0 use ﬂoored ( // integer) division.
>>> minute = 59
>>> minute//60
Output: 0

## Order of operations

When more than one operator appears in the python expression, the order of solution depends on the rules of precedence.

For mathematical operators, Python follows mathematical convention. The acronym PEMDAS is a useful way to remember the rules:

### What does PEMDAS Means?

It is a mathematical convention. It stands for parentheses, Exponentiation, Multiplication, Division addition, and subtraction.

Parentheses have the highest precedence in mathematics. Since expressions in parentheses are evaluated ﬁrst, for example,

>>> 4 * (4-3) is 4

>>> (4+1)**(8-2) is 15625

The parentheses also make an expression simple and easier to read and write, as in (minute * 100) / 60, even if it doesn’t change the result.

Exponentiation has the next highest precedence, for example,

>>> (3**1+1) is 4, not 9.

The precedence goes lower from right to left. after exponentiation, the next precedence of operators in python will be multiplication, division, and so on.

## Python operators in detail

Operators in Python are divided into the following groups:

• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators

### Arithmetic Operators in Python

Arithmetic operators in python are used to perform mathematical operations. The operations include addition, subtraction, multiplication, and division. Here is the list of arithmetic operators in python.

### Assignment Operators in Python

Assignment operators in Python are used to assign values to variables.

### Comparison Operators in Python

Comparison operators are also called python relational operators. They are used to compare two values. These operators are used in conditions that compare one expression with another.

The result of a comparison can be TRUE or FALSE. Here is list of Python comparison operators.

### Logical operators in Python

Logical operators in Python are used for conditional statements and return true or false. These operators are and, or, and not and are defined as follows:

### Identity operators in python

The identity operators in python are used to compare objects. These operators compare the memory locations of objects.

There are two identity operators.

1. is
2. is not

where the ‘ Is ‘ operator returns true if the location of objects is the same. for example, consider the example:

>>> a = 10

>>> b = 20

>>> a = b ( will returns False)

We can check the location using id(a) or id(b)

If we set ( a = 20 ) or ( a = b ) then ( a is b ) will return True.

The second identity operator ‘ is not ‘ returns the result opposite to the ‘is’ operator.

The above example ( a is not b) will return True. If we set ( a = 20 ) or ( a = b ) then ( a is not b ) will return False. This means the id(a) is equal to id(b).

### Python Membership Operators

The membership operators are used to check the presence of a sequence in an object or list etc.

consider the following example:

>>> colors = [“red”, “green”, “blue”]

>>> print(“blue” in colors) will return true because the ‘blue’ is present in colors.

There are two types of membership operators in python.

1. in ( return True if the sequence is present in the specified object)
2. not in ( returns True if the sequence is not present in the specified object)

### Bitwise Operators in Python

There are bitwise operators in python to compare the binary numbers. we can use bitwise operators to perform Boolean logic on individual bits.

Here are the bitwise operators and their descriptions in the given table.

let us consider two variables.

>>> a = 1

>>> b = 1