Python 3.x 为什么我在python中获得分步输出?
我已经编写了在这个列表中获取总计的代码,但是我得到了一个逐步的输出Python 3.x 为什么我在python中获得分步输出?,python-3.x,Python 3.x,我已经编写了在这个列表中获取总计的代码,但是我得到了一个逐步的输出 ram_list = [1111, 2222, 3333, 4444, 5555] sham_list = [6666, 7777, 8888, 9999, 909] total = 0 for item in ram_list: total = total + item print(total) o/p 所需o/p 16665 你的打印声明 for item in ram_list: t
ram_list = [1111, 2222, 3333, 4444, 5555]
sham_list = [6666, 7777, 8888, 9999, 909]
total = 0
for item in ram_list:
total = total + item
print(total)
o/p
所需o/p
16665
你的打印声明
for item in ram_list:
total = total + item
print(total) //This one
在for循环中。这会导致它在每次迭代时打印总数。如果只需要最终值,请将print语句置于for循环之外
ram_list = [1111, 2222, 3333, 4444, 5555]
sham_list = [6666, 7777, 8888, 9999, 909]
total = 0
for item in ram_list:
total = total + item
// Like this
print(total)
把打印的声明放在外面,谢谢。。这真的帮了我的忙!我很高兴能帮上忙。别忘了读书
ram_list = [1111, 2222, 3333, 4444, 5555]
sham_list = [6666, 7777, 8888, 9999, 909]
total = 0
for item in ram_list:
total = total + item
// Like this
print(total)