面试宝典
for i in "alex":
pass
print(i) # 输出x
面试题
lst = []
for i in lst:
lst.append("alex")
print(lst) # 不会打印内容 因为lst是空的,循环不起来
lst = [1,2]
for i in lst:
lst.append('alex')
print(lst) # 循环打印lst中的内容 --此循环是死循环
lst = [1,2]
for i in lst:
lst.append('alex')
print(lst) # 死循环 不会打印出内容
lst = []
for i in range(5):
lst.append([])
print(lst) # [[],[],[],[],[]]
lst = [1,2]
lst[0] = lst
print(lst) # [[...],2]