= 15
temp
if temp > 30:
print("Too hot")
elif temp > 20:
print("It's about right")
else:
print("It's cold")
print("Bye!")
It's cold
Bye!
if
elif
else
Structure= 15
temp
if temp > 30:
print("Too hot")
elif temp > 20:
print("It's about right")
else:
print("It's cold")
print("Bye!")
It's cold
Bye!
This is long
= 4
score
if score >= 5:
= "pass"
msg else:
= "fail"
msg
print(msg)
fail
use Ternary Operator instead
if condition else value_if_false value_if_true
= 7
score
= "pass" if score >= 5 else "fail"
msg msg
'pass'
and
or
not
they can be short-circuited.
= True
high_income = False
good_credit = False
student
if (high_income or good_credit) and not student:
print("eligible")
else:
print("not eligible")
eligible
= 23
age
if 18 < age < 60:
print("eligible")
eligible
def handle_float(x: float) -> None:
print("x is float")
def handle_list(x: list) -> None:
print("x is list")
def num_or_list(x: float | list) -> None:
= {
type_handler float: handle_float,
list: handle_list,
}= type_handler.get(type(x))
handler if handler:
handler(x)else:
print("Unsupported type")
2.1) num_or_list(
x is float
"x", "y"]) num_or_list([
x is list