In the heart of programming logic, we have the if statement in Python.
The if statement is a
conditional that, when it is satisfied, activates some part of code. Often
partnered with the if statement are else if and else.
However, Python's else if is shortened into elif. If statements are generally coupled with variables to
produce more dynamic content.The best way to learn new things is to take a
practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the if statement in Python:
Æ’ python command
def happy_day(day):
if day is "Monday":
return ":("
if day is not "Monday":
return ":D"
print(happy_day("Sunday"))
print(happy_day("Monday"))
√ output
:D
:(
Sign up here with your email

ConversionConversion EmoticonEmoticon