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 trialBrendan Ballon
Courses Plus Student 2,728 PointsSubscripts?
What is a subscript? We haven't learned about those and he uses it in "print(todo[index])" Please help!
2 Answers
Alex Koumparos
Python Development Techdegree Student 36,887 PointsSubscript is the term used to describe the value in square brackets when using that to access a collection like Array or Dictionary. For example, in the array myArray = [1, 2, 3, 4]
we would access the 0-th element (1) by writing myArray[0]
. The [0]
is the subscript.
Similarly, in a dictionary, such as myDictionary = ["a" : "apple", "b" : "banana"]
we could access "banana"
using myDictionary["b"]
where the key (here "b") in square brackets is the subscript.
Hope that helps.
Alex Koumparos
Python Development Techdegree Student 36,887 PointsExactly (unless you have fewer than four elements in the array, in which case you'd get an out-of-bounds error)
Brendan Ballon
Courses Plus Student 2,728 PointsBrendan Ballon
Courses Plus Student 2,728 PointsSo for example, if number = 3 and I do print(randomArray[number]) I would get the fourth value in the array?
Brendan Ballon
Courses Plus Student 2,728 PointsBrendan Ballon
Courses Plus Student 2,728 Pointsthanks!