January 2019
Beginner
318 pages
8h 23m
English
The following is the syntax for the if statement:
if test_expression: statement(s)
Here, the program evaluates the test expression and will execute statement(s) only if the text expression is true. If the text expression is false, statement(s) isn't executed.
In Python, the body of the if statement is indicated by the indentation. The body starts with an indentation and the first unindented line marks the end. Let's look at an example:
a = 10if a > 0: print(a, "is a positive number.")print("This statement is always printed.")a = -10if a > 0: print(a, "is a positive number.")Output:10 is a positive number.This statement is always printed.
Read now
Unlock full access