◐ Shell
clean mode source ↗

Python Language Tutorial => Else statement

Example

if condition:
    body
else:
    body

The else statement will execute it's body only if preceding conditional statements all evaluate to False.

if True:
    print "It is true!"
else:
    print "This won't get printed.."

# Output: It is true!

if False:
    print "This won't get printed.."
else:
    print "It is false!"

# Output: It is false!

Got any Python Language Question?

pdf PDF - Download Python Language for free



Previous Next