# Python Operators

An **operator** , in software programing, is a **symbol** that usually represents an action or process, as for example "+" is an **arithmetic operator** that represents addition. These symbols were adapted from **mathematics** and logic. **Programming languages** typically support a set of operators. These **operators** are the backbone of any program and they are used for everything from very simple functions like counting to **complex algorithms** like security encryption.

In Python, operators are **special symbols** that designate that some sort of computation should be performed. **Python** includes operators in the following categories:

- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Boolean Operators
- Bitwise Operators
- Membership Operators
- Identity operators

## Python Arithmetic Operators

Arithmetic operators are used in **mathematical expressions** . These operators take **numerical values** (either literals or variables) as their **operands** and return a single numerical value.

Operator | Description | Syntax |
---|---|---|

+ | Addition | x + y |

- | Subtraction | x - y |

* | Multiplication | x * y |

/ | Division | x / y |

% | Modulus | x % y |

** | Exponentiation | x ** y |

// | Floor division | x // y |

### Python Addition (+) Operator

The addition is taking two or more numbers and adding them together, that is, it is the total sum of 2 or more numbers.

### Python Subtraction (-) Operator

Subtracts the value on the right from the one on the left.

### Python Multiplication (*) Operator

Multiplies the values on either side of the operator.

### Python Division (/) Operator

The division is a method of distributing a group of things into equal parts.

### Python Modulus (%) Operator

The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.

### Python Floor division (//) Operator

Divides and returns the integer value of the quotient. It dumps the digits after the decimal.

### Python Exponentiation (**) Operator

Raises the first number to the power of the second.

## Python Assignment Operators

An **assignment operator** assigns a value to its **left operand** based on the value of its **right operand** . These operators do not produce values. The value of an **assignment expression** is the value assigned.

Operator | Description | Syntax |
---|---|---|

= | x = 1 | x = 1 |

+= | x += 1 | x = x + 1 |

-= | x -= 1 | x = x - 1 |

*= | x *= 1 | x = x * 1 |

/= | x /= 1 | x = x / 1 |

%= | x %= 1 | x = x % 1 |

//= | x //= 1 | x = x // 1 |

**= | x **= 1 | x = x ** 1 |

&= | x &= 1 | x = x & 1 |

|= | x |= 1 | x = x | 1 |

^= | x ^= 1 | x = x ^ 1 |

>>= | x >>= 1 | x = x >> 1 |

<<= | x <<= 1 | x = x << 1 |

## Python Comparison Operators

Comparison operators, as their name implies, allow you to **compare two values** . These operators compare the contents in a field to either the contents in another field or a **constant** . They may be used alone or in combination with other operators and functions in both record expressions and target **field expressions** .

Operator | Description | Syntax |
---|---|---|

== | Equal | x == y |

!= | Not equal | x != y |

> | Greater than | x > y |

< | Less than | x < y |

>= | Greater than or equal to | x >= y |

<= | Less than or equal to | x <= y |

## Python Logical Boolean Operators

Boolean Logic is a form of **algebra** which is centred around three simple words known as Boolean Operators: **"Or"** , **"And"** , and **"Not"** . At the heart of Boolean Logic is the idea that all values are either **true** or **false** . When they are, they return a Boolean value

Operator | Description | Syntax |
---|---|---|

and | True if both the operands are true | x and y |

or | True if either of the operands is true | x or y |

not | True if operand is false | not x |

## Python Bitwise Operators

Bitwise operators treat their operands as a sequence of **32 bits** (zeroes and ones), rather than as decimal, **hexadecimal** , or octal numbers. It works efficiently and are used to perform **bitwise operations** on binary patterns. All the binary operators are in-fix except for the not operator. Typically, bitwise operations are substantially faster than **division** , several times faster than multiplication, and sometimes significantly faster than **addition** .

Operator | Description | Syntax |
---|---|---|

& | Bitwise AND | x & y |

| | Bitwise OR | x | y |

^ | Bitwise NOT | x ^ y |

~ | Bitwise XOR | ~x |

<< | Bitwise right shift | x>> |

>> | Bitwise left shift | x<< |

## Python Membership Operators

Membership operators are operators used to validate the **membership of a value** . This operator is used to test **memberships in variables** such as strings, integers as well as tuples. These operator returns either **True** or **False** , if a value/variable found in the list, its returns True otherwise it returns False.

Operator | Description | Syntax |
---|---|---|

in | True if value is found in the sequence | x in y |

not in | True if value is not found in the sequence | x not in y |

## Python Identity operators

Identity operators are used to **compare the objects** , not if they are equal, but if they are actually the same object, with the same **memory location** . They are usually used to determine the type of data a certain **variable contains** .

Operator | Description | Syntax |
---|---|---|

is | True if the operands are identical | x is y |

is not | True if the operands are not identical | x is not y |