if Statements In Python
A SIMPLE EXAMPLE
cars = ['toyota','honda','byd','buick']
for car in cars:
if car == 'byd':
print(car.upper())
else:
print(car.title())Toyota
Honda
BYD
Buick1. CONDITIONAL TESTS
1.1. Checking for Equality
Ignoring Case When Checking for Equality
1.2. Checking for Inequality
1.3. Numerical Comparisons
Using various mathematical operators
Operator
Meaning
1.4. Checking Multiple Conditions
Using and condition
and conditionUsing or condition
or condition1.5. Checking Whether a Value is in a List
in a List1.6. Checking Whether a Value is not in a List
not in a List1.7. Boolean Expressions
2. Types of if STATEMENTS
2.1 Simple if Statements
if Statements2.2. if-else Statements
if-else Statements2.3. The if-elif-else Chain
2.4. Using Multiple elif Blocks
2.5. Omitting the else Block
2.6. Testing Multiple Conditions
2.7 STYLING YOUR if STATEMENTS
if STATEMENTS3. USING if STATEMENTS WITH LISTS
3.1 Checking: an item inside list
if statement inside the for loop
if statement inside the for loop3.2. Checking: List Is Not Empty
Combining two if-else statements block
3.3. Using Multiple Lists
Last updated