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 with Basic For Loops

Gavin Donathan
Gavin Donathan
Python Development Techdegree Student 2,558 Points

for 1 in groceries: looping

Hello everyone,

I have a question in reference to the for in loop topic. name = 'dog' for i in name: print(i) This prints out each letter respectively. I tried this with different letters and words, but I am unable to assign a number in place of the (i).

Why is this?

If the i/(letter) chosen is simply associated with the sequence of the given variable or list at times, why does it not accept numbers?

Just curious.

Thank you all for your time and thoughts!

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

Hey Gavin Donathan, the short answer is numbers are immutable and cannot be used as variable names. No variable name can begin with a digit. See docs:

Within the ASCII range (U+0001..U+007F), the valid characters for identifiers are the same as in Python 2.x: the uppercase and lowercase letters A through Z, the underscore _ and, except for the first character, the digits 0 through 9.

Post back if you have more questions. Good luck!!