-2

My code: text = [['Name', 'Surname', '2009']]

What I tried to do: text[1];

I want so that the 'Surname' would print out, but I keep getting - IndexError: list index out of range.

lucutes
  • 9
  • 3
  • 1
    You have a list *of list*. `text[0][1]` would be `'Surname'`. – jonrsharpe Mar 27 '20 at 14:23
  • This is a list within a list. so text[0] will give you the inner list then you need [1] to acces sindex 1 of the inner list. So text[0][1] says access the list in index 0 or text then access surname in index 1 of the inner list – Chris Doyle Mar 27 '20 at 14:26

1 Answers1

1

This is a nested list.

text = [['Name', 'Surname', '2009']]

text[0] = ['Name', 'Surname', '2009']

text[0][1] = 'Surname'
Viswa
  • 316
  • 1
  • 14