how to only print final iteration of a for loop pyhton

Solutions on MaxInterview for how to only print final iteration of a for loop pyhton by the best coders in the world

showing results for - "how to only print final iteration of a for loop pyhton"
Lilli
19 Jul 2020
1prices = [10, 20, 30]
2total = 0
3for price in prices:
4    total += price
5	#print(f'total: {total}') will give all iterations in order
6print(f'total: {total}') #make sure to print outside of loop for 
7#only final iteration to print