IF – STATEMENT IN PYTHON

Photo of author

By Jackson Taylor

SIMPLE IF –PROGRAM

x=3 ;
if x==3:
print 'hai'
print 'hai'

OUTPUT

hai
hai

IF ELSE –PROGRAM

x=2 ;
if x==3:
print 'hai'
elif x>1 :
print 'hhh'

OUTPUT

hhh

NESTED IF –PROGRAM

x=2 ;
if x==3:
print 'hai'
elif x>1 :
    print 'hhh';
    if x>0:
        print 'hhh';

OUTPUT

hhh
hhh

more examples

See also
LED CONTROLLING USING ARDUINO AND PYTHON

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works