if boolean_expression: No "then". stmt(s) the "body" or "block" of the if. Must be indented.semantics: "meaning"/behaviour:
use:
execute a set of code (the body) if some condition is
met (is True). Don't execute the set of code if the condition
is False.
The expression is a condition of some sort. A question that is true or false.
Relational operators in Python: < > <= less than or equal (no ≤ key on keyboard) >= greater than or equal == equality Single = is assignment operator. Don't confuse them! != not equalsAn expression with a relational operator evaluates to True or False:
a < b this expression's value is True or False.Every expression will have a single value of a particular type when evaluated.
if gpa > 3.5: print("Dean's list") ------------------- if y != 0: #divide by y only if not zero x = 1 / y ------------------- if y != 0: x = 1 / y #indent all statements of the body print("Reciprocal is:", x)
if boolean_expression: stmt(s) else: #if the expression is not True, # execute the statements of the else part. stmt(s) # in an if else, either the if body or # the else body will be executed, one # or the other but not both