Skip to content

Instantly share code, notes, and snippets.

@fahdi
Created February 6, 2023 23:14
Show Gist options
  • Save fahdi/d768eaf5c0bb9d0459490a277d17ea4a to your computer and use it in GitHub Desktop.
Save fahdi/d768eaf5c0bb9d0459490a277d17ea4a to your computer and use it in GitHub Desktop.
Python Negative Indexes
class_name_test =[
["Jenny", 90],
["Alexus", 85.5],
["Sam", 83],
["Ellie", 101.5] # <---- [-1][-1]
# Can be done in many ways but that's not what they wanted
]
print(class_name_test)
# x axis and y axis
# Sam's 'x axis value is class_name_test[2]
sams_score = class_name_test[2][1]
print(sams_score)
#Since Ellie is the last one, we gotta use the -1 to denote that!
ellies_score = class_name_test[-1][-1]
print(ellies_score)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment