Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introducing Lists!
You have completed Introducing Lists!
Preview
Now that we have stuff in our list, how do we access specific elements. Through indexing! Let's explore.
Code
books = [
"Automate the Boring Stuff with Python: Practical Programming for Total Beginners - Al Sweigart",
"Python for Data Analysis",
"Fluent Python: Clear, Concise, and Effective Programming - Luciano Ramalho",
"Python for Kids: A Playful Introduction To Programming - Jason R. Briggs",
"Hello Web App: Learn How to Build a Web App - Tracy Osborn",
]
Learn more
- PEP8 - When to Use Trailing Commas (Immerse yourself...reminder, it's okay if you don't understand everything!)
- Great StackOverflow Answer on why to use trailing commas
For Fun
- Rapping Raisins - Books, Check 'em out (Yes, that is Sir Mix-A-Lot)
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
you can refer to a specific element
through what is known as indexing.
0:00
Every element in your list
is assigned a number.
0:03
And you can access them by an opening
hard bracket followed by a number
0:05
representing which element you want and
a closing hard bracket.
0:09
We'll explore accessing
elements here in a bit but
0:13
first, let's tackle a common
problem that happens when indexing.
0:15
Indexing in Python is zero based.
0:19
What this means is that the first element,
0:22
which most likely you would assume
to be one, is actually zero.
0:24
And the second element that you would
probably assume is two, it's actually one.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up