A computer program often requires a decision or a branch within a code to account for how the code operates under different inputs or conditions.
Within the Python programming language, the simplest and sometimes the most useful way of creating a branch within your program is through an if
statement.
The syntax for writing an if
statement is as follows:
Let’s take a look at an example implementing an if
statement:
#creating variables "a" and "b" a = 500 b = 200 #if condition to check whether "a" is greater than "b" if(a > b): print "a is greater than b"
The illustration below explains the code above.
RELATED TAGS
View all Courses