循环
1、for循环
for变量 in range(起点,终点,步长):(只有一个值是表示终点,省略其他)
循环体
2、while循环
起点
while 表达式(bool)/终点:
循环体
步长
例1,用for循环 写出 九九乘法表
for i in range(1,10):
for j in range(1,i+1):
print(j,"*",i,"=",i*j," ",end="")
print()
例2,用while循环 打印菱形
i = -4
while i<5:
j=0
while j<abs(i):
print(" ",end="")
j += 1
k = 0
while k < 9-2*abs(i):
print("*",end="")
k += 1
i += 1
print()
list列表[ ]
取值 print(a[2])
存值(元组中不能改只能列表进行)
a[0]=“…”
a(0)=“…”(元组不能更改!)
tuple()元组 末尾追加元素
a.append("…") 注:元组末尾不可追加
列表元组遍历:
- for i in range(6):
print(q[i]) - for item in q:
print(item)
3.print(q/p)