Python

5 Python Conditional Statements 3 – Condition operators or symbols

Condition symbols or operators

Operators evaluation:

1) == Equal to operator - True when matches - False when don't match.
CASE == CASE (matches and True in this case)
Name = 'Vijay'
Name == 'vijay' (False)
Age = 18
Age == 18 (True)

2) != not equal to operator
- True when matches - False when don't match.
CASE != case (matches and True in this case)

Name = 'Vijay'
Name != 'vijay' (True)
Age = 18
Age != 16 (True)


3) < less than operator
> greater than operator
<= less than equal to operator
>= greater than equal to operator

- True when matches - False when don't match.

Multiple Conditions:

and ...or...not..in..not in operators
age = 20
age1 = 30
age2 = 35
------------------------------
and operator
if (age >= 15 and age1 >= 15)
Results to : False
if (age3 >= 15 and age1 >= 15)
Results to : True
---------------------------------
or operator
if(age >= 15 or age1 >= 15)
Results to : True
if (age3 >= 15 or age1 >= 15)
Results to : False
Checking whether a value is in the list or not in the list; using in and not in operator

age = [20,30,40,50,60]
vjays_age = 18
20 in age
returns True
80 in age
returns False

if vjays_age not in age: (evaluates True)
print("You cannot participate in this group")

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s