Skip to content

Python code snippet – How to only print final iteration of a for loop pyhton?

prices = [10, 20, 30]
total = 0
for price in prices:
    total += price
	#print(f'total: {total}') will give all iterations in order
print(f'total: {total}') #make sure to print outside of loop for 
#only final iteration to print
See also  Python code snippet - How to rewrite minute in datetime ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.