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 Using Databases in Python Meet Peewee Queries Are Your Friend

rajan lagah
rajan lagah
2,539 Points

how 0.username work ?

we return student but use 0.username. how does it work?

3 Answers

Josh Keenan
Josh Keenan
20,315 Points

0 isn't the list it is the index, it isn't necessarily a list either. It is the first part of the output from the function called in the .format(), it looks for the first part of the output and takes that, in this case it is what we are looking to return and the function returns just one things, if you made it return two things you could use the 1 index.

Josh Keenan
Josh Keenan
20,315 Points

My understanding is that is is accessing the 0th index (the first item) that is returned from the function in format, then it gets the username from this object and returns it

rajan lagah
rajan lagah
2,539 Points

u are right boss. when i tried 1.username it give index out of bond . but how 0 can b list or etc. i cant digest that .

Dmitriy Ignatiev
PLUS
Dmitriy Ignatiev
Courses Plus Student 6,236 Points

I guess that is more simple that we think. My view is that when we call top student() it return a tuple (username, points) from our list and to have access to username or the points we need first indicate index of tuple or dict and this always be 0 if use get() and then we pass a key what information we would like to show 0.points or 0.usrename or both.