while loop is used to excute a block of code multipule times.
for loop is used to iterate items of a collection. The collection can be a string, a list, or a range of objects. Each time create a new object and iterate it
计算总价
prices =[10,20,30]sum=0for price in prices:sum+= item
print(f'sum: {sum}')
嵌套循环形成F形(假设数字与字符串不能相乘
numbers =[5,2,5,2,2]
result =''for number in numbers:for i inrange(number):
result +='x'
result +='\n'print(result)
while loop is used to excute a block of code multipule times.for loop is used to iterate items of a collection. The collection can be a string, a list, or a range of objects. Each time create a new ...