Function of "return" in loop


#1

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096

Actually, I understand the exercise, but I have a question about the "loop" . Please see the example in this lesson.

What does " return total " play in the "loop"? Since "for .... in ...." loop has already operated every item in the list, it can repetitively play the item in the list. So what will be the result if there is no "return total" in the end?


no code, just question about the example


#2

well, the loop will stop eventually since it will run out of items.

then nothing would happen, since you don't do anything with total.

With such questions, it is still nice to include code so we can see it, this really helps to help you :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.