A Python newbie ask a simple question

Jeff McNeil jeff at jmcneil.net
Fri Jul 13 20:51:52 CEST 2007


The raw_input built-in returns a string.  The '[0]' subscript returns
the first character in the user supplied response as strings support
indexing.

[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> mystr = "asdf"
>>> mystr[0]
'a'
>>>

>>> raw_input("Another one, please: ")[0]
Another one, please: ASDF
'A'
>>>

-Jeff

On 7/13/07, xing93111 at gmail.com <xing93111 at gmail.com> wrote:
> what does the statement "choice = raw_input(prompt)[0]" mean? I don't
> know why there is a '[0]' in the statement.
>
> Thank you very much
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list