### What are the Python operators?

A Python operator is used to perform a specific operation on a variable or value. The assignment operator is the most common type of operator, however, we have other types of operators such as:

- Arithmetic operators
- Comparison operators
- Logical operators
- Identity operators
- Membership operators
- Identity operators
- Bitwise operators

Python operators come in a few different guises. The main ones that you’ll be looking at are the mathematical ones and probably the comparison operators. But there are a few others that are quite useful and in this article, we will run through some of the more common ones and the basic ones.

## Arithmetic Python operators

Arithmetic operators include operations like simple additions, subtractions, multiplication, exponential and division. If we initialize x to be equal to five and y to be equal to 10 we can illustrate the arithmetic operators, for instance, x plus y is a simple addition while a dash is used to denote subtraction. Multiplication is denoted with a star sign and double star signs represent exponentiation and finally, a forward slash represents divisions as shown in the code below.

## Comparison operators

Comparison operators are used to comparing two values.

### Double Equal to

When comparing two values we use double equal signs since a single equal sign is an assignment operator. The equal to comparison operator is used to test if the value on the left-hand side is indeed equal to that on the right side, if they are equal then it returns the boolean True and False if otherwise.

In this case, False is returned since x is not equal to y. However, if we change the value of y to be equal to 5 then True will be returned since in that case, y will be equal to x.

This is particularly useful when working with code and you need to see if something is equal to something else.

Comparison operators can be used together with strings as well. If we equate x to be equal to the string ‘lion’ in this case if we compare it with the variable y then we will get the boolean value False.

In theory, we could have the same strings and in that case, it is going to return the value True instead as shown below.

### Not Equal to

This is another useful comparison operator known as the not equal. This comparison operator is denoted by an exclamation mark that is then followed by an equal sign. To demonstrate this python operator we are going to turn back to the integer values that we had used initially.

This returns true because x does not equal y. If we change these values again such that they are equal, this returns false because the statement that x is not equal to y Is false. Because the two values are the same.

## Logical Python Operators

We can also use multiple statements to compare more than two values. To demonstrate this let’s add a couple of numbers. Let’s do ‘c’ is equal to eight and i is equal to 15 and will change y to 10 as well. The keyword ‘and’ and ‘or’ can be used to compare multiple values and return boolean statements accordingly. So we could say if x does not equal to y and c is equal to I.

This statement is returning false even though x is not the same as y, c is not the same as i, so the whole statement is false.

We can also use or so this will be this one or this one, so this will return true because x is not equal to y.

## Membership Python Operators

Membership operators are used to testing if a sequence is present in a particular object.

There are two types of membership operators: the ‘in’ operator returns True if a sequence with a specified value is present in an object while the ‘not in’ returns ‘True’ if the sequence with a specified value is not present in an object.

We can change the value of x to be equal to ‘i’ and y to be equal to ‘tiger’

So what we could do is we could say is x in y.

This is equal to true because it has found the value of x within the y statement

Conversely, you can also have not in as shown below.

And we can see that that’s returning false there. So if we change the letter ‘i’ to ‘o’, we can see that it returns True.

## Summary

If you’d like to see **more programming tutorials,** check out our **Youtube channel, **where we have plenty of Python video tutorials in English.

In our Python Programming Tutorials series, you’ll find useful materials which will help you improve your programming skills and speed up the learning process.

## Programming tutorials

- How to use the Python for loop
- How to use Python Sets
- How to use a Python Dictionary
- How to use Python Classes
- How to use Python Range
- How to use Python if-else statements
- How to use Python RegEx
- How to use Python Lists
- How to use Python Enumerate
- How to use Python Functions
- How to use Python Split
- How to use Python Try-Except
- How to use Python Tuples
- How to use Python Arrays
- How to use Python Sort
- How to use the Python DateTime
- How to download Python?
- How to use the Python FileWrite function
- How to use Python Lambda
- How to use Python ListAppend
- How to use Python ListComprehension
- How to use Python Map
**How to use Python Operators**- How to use Python Pandas
- How to use Python Requests
- How to use Python Strings
- How to use Python Count
- How to use Python Comments
- How to use the Python File Reader method
- How to use the Python IDE-s
- How to use Python logging
- How to use Python Print
- How to use the Python Zip
- How to use Python Append
- How to use Python Global Variables
- How to use the Python join method
- How to use Python list length
- How to use Python JSON files
- How to use Python Modulo
- How to use Python file opening methods
- How to use Python round
- How to use Python sleep
- How to use Python replace
- How to use Python strip
- How to use the Python Time module
- How to use Python unittests
- How to save data to a text file using Context Manager?
- How to use Python external modules
- How to use Python find
- How to use the Python pip package manager
- How to delete files in Python
- Parsing XML files in Python
- How to make a GUI in Python
- How to use Python in Command Prompt
- How to Run a Python Program in VS Code
- How to run a program in Python IDLE
- How to run a program in Jupyter Notebook
- How to read a text file in Python
- How to add numbers in Python
- How to ask for user input in Python
- How to debug in Python
- How to create a thread in Python
- How to import a library in Python
- How to use the PIP package manager
- How to use classes in Python
- How to reverse strings in Python
- How to convert a string to int in Python
- How to print on the same line in Python
- How to remove items from a list
- How to add to a dictionary in Python
- How to raise an exception in Python
- How to throw an exception in Python
- How to stop a program in Python
- How to use Python assert
- How to use the Python compiler

Would you like to learn how to code, online? Come and try our first 25 lessons for free at the CodeBerry Programming School.