[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Basic Python string slicing (was: Re: [pygame] Pygame Render Text as Variables)



"Ian Mallett" <geometrian@xxxxxxxxx> wrote:
> Do you mean like:

You don't include the post that you're replying to, Ian, so it can be
difficult to follow your posts.


> my_string = "Python"
> first_letter = my_string[0]
> last_letter = my_string[:0]
> #  first_letter == "P", last_letter == "n"
>

You probably mean
last_letter = my_string[-1]

right? Because my_string[:0] is the slice of my_string up to, and not
including the zeroth element, which is '', the empty string.

-Dave LeCompte