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

What happened to, the sequence of "0,1,2,3..." ?

when you write the unpacking sequence, I noticed it doesn't follow the tradition computer lanugage of 0 being the first value, if this is the case, how does python know that when you write:

'var1, var2, var3' = unpacker()

equals: unpacker() return 'hey' h >>>> wouldn't this technically be 'var0' ?? e y

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

Python uses 0-based indexing so zero is the first index.

The names of objects have no numbering restrictions.

var1 within the tuple var1, var2, var3 would be referenced by index 0:

>>> string = 'hey'
>>> string
hey
>>> string[0]
h
>>> v1, v2, v3 = string
>>> v1
h
>>> (v1, v2, v3)
(h, e, y)
>>> (v1, v2, v3)[0]
h

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

That's helpful to know, thank you for sharing that, makes sense now