python中For循环

打印出1到100的数,不包含100

for i in range(1,100):

if i==23:

print "great,you got your luncky number:",i

print 'The unmber is:',i

================23会被重复打印===============================



for i in range(1,100):

    if i==23:

           print "great,you got your luncky number:",i

    else:

           print "The unmber is:",i

================23只会打印一次===============================



for i in range(1,100):

if i==23:

print "great,%s lucky number:"%i  #%s,引用外部的变量;外部的变量则为:引号之外的变量

print "The number is:",i


你可能感兴趣的:(python,循环,for)