Python statements : if, for, while, continue, break, pass, print
IF statement
x = 7

if x == 5:
    print ("X is 5")
elif x == 3:
    print ("X is 3")
else:
    print ("X is neither 3 nor 5")   
FOR statement
letters = ['a1', 'a2', 'a3', 'a4']

for letter in letters:
    print (letter)

print ("Another way of using FOR")

for letter in letters[:]:
    print (letter)

print ("FOR using RANGE function")
for i in range (5):
    print (i)
WHILE statement
    i = 6
j = 0

while j < i:
    print (j)
    j = j + 1
DO ... WHILE statement
// There are no do while statement in Python.
CONTINUE statement
print ("Odd print")
i = 0
while i < 20:

    if (i % 2) == 1:
        i += 1
        continue
    else:
        i += 1
    print ("i is 4 ", i)

print ("Even print") 
i = 0
while i < 20:

    if i % 2 == 0:
        i += 1
        continue

    i += 1
    print ("Even : ", i)
BREAK statement
i = 1

while i < 20:
    print ("i is ", i)
    i += 1

    if i == 15:
        break

print ("Exited at", i, "using BREAK statement")
PASS statement

PASS does not do anything, it is used as : for Shell Script

pass
PRINT statement
print ('value', sep=' ', end='\n', file=sys.stdout)

print ("hello World")

print ("hellow \n world")

print (r"hellow \n world")

print ("hello \
world \
newline")

print("""\
Usage: thingy [OPTIONS]
     -h                 Display this usage message
     -H hostname        Hostname to connect to
""")

print (30 * "___ ")

print ('Py' 'thon')

print ('Hellow' + ' World')
SUBSTRING statement
    
    s = "123456789"

print (len (s))

s1 = "hello"
s2 = "world"
s3 = s1 + ", " + s2
print (s3)

a = "123456789"

substr1 = a[0:2]
print (substr1)

substr1 = a[:5]
print (substr1)

substr1 = a[5:]
print (substr1)

substr1 = a[-1]
print (substr1)

substr1 = a[-2]
print (substr1)
Comments