一、for 循环语法
循环字符串:
str = 'hello'
for x in str:
print(x ,end=' ')# end="-" end="+"
#h e l l o -----end=' '
#h-e-l-l-o -----end="-"
#h+e+l+l+o -----end="+"
循环列表:
a = ["h","e","l","l","o"]
for x in a:
print(x)
二、break 和 continue
for x in str:
print(x)
break
print(123)
for x in str:
print(x)
continue
print(123)
三、for...else...组合使用
for x in str:
print(x)
else: #如果for正常循环完才执行else,如果遇到错误,break等,则不执行
print("答应完成")
四、打印九九乘法表
for i in range(1,10):
for j in range(1,i+1):
print('%s*%s=%s' %(i,j,i*j),end=' ')
print()