['a', 'b'][True] results 'b' But how?

rishi pathak mailmaverick666 at gmail.com
Thu Jul 5 03:26:39 EDT 2007


True stands for 1 and False stands for 0
so list[True] is equivalent to list[1]
and list[False] is equivalent to list[0]

On 7/5/07, kath <nitte.sudhir at gmail.com> wrote:
>
> Hi,
>
> 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.
> How is it making effect....?
> <code Python24>
>
> >>> ['a','b] [True]
> 'b'
> >>> ['a','b'] [False]
> 'a'
> >>> ['a','b']['some_string' == r'some_string']
> 'b'
> >>> ['a','b']['some_string' == r'somestring']
> 'a'
>
> <code>
>
>
> Thanks in advance,
> regards,
> kath.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070705/8f6bceca/attachment.html>


More information about the Python-list mailing list