['a', 'b'][True] results 'b' But how?
Robert Bauck Hamar
roberth+news at ifi.uio.no
Thu Jul 5 09:23:38 CEST 2007
> Can any one please tell me how is the following code is working?
> ['a','b'] is a list of string
> and [True] is list of boolean value.
No. It's the subscription operator applied to the list of strings.
a = ['a', 'b']
may be clearer.
> How is it making effect....?
>>> isinstance(True, int)
> <code Python24>
>>>> ['a','b] [True]
>>>> ['a','b'] [False]
>>>> ['a','b']['some_string' == r'some_string']
>>>> ['a','b']['some_string' == r'somestring']
More information about the Python-list