IF, ELSE or ELIF (known as else if in some programming) are conditional statements which are used for execution of different code depends on condition. The if statements can be written without else or elif statements, But else and elif can’t be used without else. In this tutorial, you will learn if, else and elif in Python programming language. 1. Python if Statement The single if statement is used to execute the specific block of code if the condition evaluates to true. In the case of false output, nothing will execute. Syntax:
1 2 | if ( condition ): statements |
Example 1:
1 2 3 4 5 | #!/usr/bin/python var = 101 if ( var ): print "true" |
Example 2:
1 2 3 4 5 | #!/usr/bin/python var = 101 if ( var==101 ): print "true" |
2.…