Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Sequences Sequence Iteration Iterating over Ranges

stuck on this question: my_list = [] - iteration with stop value of 10 to append a value use my_list.append()

possible answer:

my_list = []
for i in range(10):
my_list.append(i)

not exactly sure why this passes for the challenge vs.

my_list = []
for i in range(0, 10):
      print(i)

I reviewed both videos twice and I just can't seem to grasp this concept...

[MOD: added ```python formatting]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hi imjane, the difference is the second solution prints the loop value, but does not change the contents of my_list. Without the append the value of my_list does not change. Hence, the checker will not see the expected list contents in the list my_list.

Post back if you need more help. Good luck!!

thanks Chris. I was not understanding that the append could be used as another method of changing value in my_list.