代码示例如下:
old_prices = [10, 20, 30, 40] new_prices = [10, 25, 30, 50]
for i in range(len(old_prices)): if old_prices[i] == new_prices[i]: print(f"The price of element {i+1} hasn't changed.") else: print(f"The price of element {i+1} has changed from {old_prices[i]} to {new_prices[i]}.")
输出结果为:
The price of element 1 hasn't changed. The price of element 2 has changed from 20 to 25. The price of element 3 hasn't changed. The price of element 4 has changed from 40 to 50.
下一篇:比较每个字符的字符串列表