# L6 - Conditional Expressions

# if statement in python

![1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660641152422/9IjyCEc7f.png align="left")

## Indentation

Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose. **if statement without identation will raise an error, in python identation for if elif else statement is (TAB) i.e four whitespaces.**

![2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660641409459/Vq3Jl734w.png align="left")

# if elif statements in python

*elif* means else if .

```plaintext
a = 200
b = 203
if(a>b):
    print('The value of a is greater than b')
elif(b>a): 
    print('The value of b is greater than a')
```

```plaintext
The value of b is greater than a
```

# if elif else statements in python

```python
a = 100
b = 100
if(a>b):
    print('The value of a is greater than b')
elif(a<b):
    print('The value of a is lesser than b')
else:
    print('The value of a is equal to b')
```

```plaintext
The value of a is equal to b
```

**You can also use else without elif and can transform it into a if else statement.**

# Relational Operators

* **\==** means equals
    

\*\* &gt;=\*\* means greater than or equals to

## \*\* &lt;=\*\* means less than or equal to

**\&gt;** means greater than

**&lt;** means less than

# Logical Operators

\*\*AND \*\* - Returns True if both the conditions are met .

\*\*OR \*\* - Returns True if any one of the conditions is met.

**NOT** - Inverts true to false and false to true.

## AND OPERATOR

The and keyword is a logical operator and is used to combine conditional statements.

```plaintext
a = 40
b = 32
c = 39

if (a>b) and (a>c) :
    print('Value of a is greater than b and c ')
else : 
    print('a  is not the greatest number among a,b and c')
```

```plaintext

Value of a is greater than b and c
```

## OR OPERATOR

```plaintext
a = 30
b = 32
c = 30

if (a>b) or (a<c) :
    print('Value of a is either greater than b or less than c')
else:
    print('Condition not satisfied')
```

```plaintext
Condition not satisfied
```

# Nested if statements

Using if statements inside if statements is called nested if statements.

```plaintext
a = 30
b = 291
c = 32

if (a<b):
    print('a is less than b')
    if (a<c):
        print('a is less than c')
else:
    print(a)
```

```plaintext
a is less than b
a is less than c
```

## using IN and IS

### using in

```plaintext
A = None

if ( A is None ): 
    print('yes')
else:
    print('a is not none')
```

```plaintext
yes
```

### using is

```plaintext
a = [1,2,3,333,34,69]

if (333 in a):
    print('yes')
else:
    print('333 is not in a ')

# METHOD - 2
print(5555 in a)    
print(3 in a)
```

```plaintext
yes
False
True
```
