Decision-making is the way where a program shift execution from one side to another based on a condition if the condition evaluates to True then the next statement(s) will be executed other wise if there is any else statement its block(or body) will be executed instead.
True vs False vs not
All non 'None' values, not empty string, non-zero numbers, whitspace-only strings, and not False values are True
All None, empty string, False values are considered False
not keyword is used to counter the condition value:
#!/usr/bin/env python if not True == False: print("not True equals False") if not False == True: print("not False equals True")
not True equals False not False equals True
if statementsAn if statement consists of a boolean expression followed by one or more statements.
if...else statementsAn if statement can be followed by an optional else statement, which executes when the boolean expression is False.
Nested if statementsYou may use one if or else if statement inside another if or else if statement(s). however keeping decision flow flat and simple is encouraged
#!/usr/bin/env python home = 'coderme.com' if 'coderme' in home: print("Home contains 'coderme'")
Home contains 'coderme'