Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 67,736 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.