Reputation: 43
i'm self learning python through out online courses but i ran into a problem .
for loop
how do i tell python to do something after the for loops is finished ?
for example :
def mixer(g):
print(g)
def printer(h):
print("end")
X = input ("words : ")
var2 = ""
var1 = X.split()
for y in var1:
if len(y) > 5:
y.upper()
var2 += y.upper() + " "
mixer(var2)
elif len(y) <= 5:
y.lower()
var2 += y.lower() + " "
mixer(var2)
that's what i'm trying to do after for loop is done , i want to call a function after the loop , how can u do this ? ## >>> this method didn't work
elif y == False:
print("false")
printer(var2)
Upvotes: 0
Views: 4191
Reputation: 155684
Just put it outside the body of the for loop:
for x in y:
... indented block does stuff with x on each loop ...
... dedented code (outside loop body) run once after loop is finished ...
Upvotes: 1