python中的for循环

时间:2022-03-12 06:44:54

打印出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