if else Statement
Like other languages, Python features an else statement that can be paired with an if statement. The else statement identifies a block of code to be executed if the conditional expression of the if statement resolves to a false Boolean value. The syntax is what you expect:
if expression: expr_true_suite else: expr_false_suite
Now the obligatory usage example:
>>> username = "john" >>> password = "123" >>> if username == "john" and password =="123": print "Hello john" print "welcome to python" else: print "access denied" Hello john welcome to python >>> if username == "john1" and password =="123": print "Hello john" print "welcome to python" else: print "access denied" access denied