Hello, I am trying to teach myself python. I am needing a little clarification on this:
a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b'
I understand up until the >>> x[0] results being [‘a’, ‘b’, ‘c’]
I even understand the next line …[1] being ‘b’
Maybe it is so obvious that I am over complicating it. IDK
Does the zero mean all characters after the zero position?
Thanks for any help!
Because (as I say), you have a ‘nested list’: that is to say you have two list object, within another list object. So, [0] is returning ‘the first list object’.
x = [a, n] has created a list object that contains the other two list objects.
Because (as I say), you have a ‘nested list’: that is to say you have
two list object, within another list object. So, [0] is returning
‘the first list object’.
x = [a, n] has created a list object that contains the other two list
objects.
To make this a bit more clear maybe, your first post showed this:
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
Laid out more elaboratedly:
[
['a', 'b', 'c'], # this is x[0]
[1, 2, 3] # this is x[1]
]