November 2017
Beginner to intermediate
204 pages
5h 23m
English
An if statement is a compound statement that allows you to run a block of code conditionally. This means that if a certain condition is met, the code will run; otherwise, it will not. If statements have the following syntax:
if <booleanValue>: <code block>
The Boolean value in the clause header is the condition of the if statement. If the Boolean value is True, then the code block is run. If the Boolean value is False, then the code block is not run. In the following example, the program will print "Nice Weather!" if the value of the isSunny variable is True:
isSunny = Trueif isSunny: print("Nice Weather!")
In the next example, the value of isSunny is changed to False, so nothing will happen:
isSunny = Falseif isSunny:> print("Nice ...Read now
Unlock full access