Python Conditions and If statements
Python Conditions and If statements
"if statement" is written by using the if keyword.
"if statement" is written by using the if keyword.
Example a = 33 b = 200 if b > a: print("b is greater than a")
Example a = 33 b = 200 if b > a: print("b is greater than a")
Python relies on indentation (whitespace at the beginning of a line) to define scope in the code
Python relies on indentation (whitespace at the beginning of a line) to define scope in the code
a = 33
b = 200
if b > a:
print("b greater than a")
a = 33
b = 200
if b > a:
print("b greater than a")
ELIF:-
The elif keyword is Python's way of saying "if the previous conditions were not true, then try this condition".
ELIF:-
The elif keyword is Python's way of saying "if the previous conditions were not true, then try this condition".
Example
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Example
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Else The else keyword catches anything which isn't caught by the preceding conditions.
Else The else keyword catches anything which isn't caught by the preceding conditions.
Example a = 200 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b")
Example a = 200 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b")
You can also have an else without the elif: a = 200 b = 33 if b > a: print("b is greater than a") else: print("b is not greater than a")
You can also have an else without the elif: a = 200 b = 33 if b > a: print("b is greater than a") else: print("b is not greater than a")
DATA ANALYTICS TRAINING AND PLACEMENT
DATA ANALYTICS TRAINING AND PLACEMENT