Python Not Boolean Operator Tutorial – POFTUT

# Python Not Boolean Operator Tutorial

Python provides wide range of the logical operators. One type of logical operator is boolean operators where we can check the similarity or equality of the given data or variables. In this tutorial we will examine the `not` Boolean operator which can be used inequality of the provided values or data.

# Check If Not Equal

We will start with a simple example where we will check whether given variable `age` is `10` . We will use `not` operator. We should use `not` operator with `is` operator like below.

```age=9
if(age is not 10):
print("Age is not 10")```

# Not Operator Sign !=

We have alternative way to express `not` logic. We can use `!=` operator sign the same fashion as `not` . We will use previous example again with `!=` which check if the age variable is not 10.

```age=9
if(age != 10):
print("Age is not 10")```

# Check If Not Exist In Given List or Array

Another useful usage case for `not` operator is checking given value or variable against a list or set. In this example we will check whether variable a value exist in the given list.

```numbers=[1,3,5,7]
if 2 not in numbers:
print("2 is not in numbers list")```

# Not Not

As `not` is logical operation we can use it multiple times in a single expression. In this example we will `not` two times for single value. In this case we will not True value two times. At first it will be false but with the second not it will be `True` again.

```status=not not True
print(status)```
We can also `not` given data or variable. In this case we will `not` number `10` and check if equal with `10` .
```if not 10 == 10: