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

Gavin Donathan
seal-mask
.a{fill-rule:evenodd;}techdegree
Gavin Donathan
Python Development Techdegree Student 5,296 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
MOD
Chris Freeman
Treehouse Moderator 68,423 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!!