string methods

Brian Beck exogen at
Sat Jul 30 18:31:49 CEST 2005

anthonyberet wrote:
> I know this touches on immutability etc, but I can't find string methods
> to return the first 3 characters, and then the last 2 characters, which
> I could concatenate with newchar to make a new string.

As tiissa said, you want slicing:

py> s = "foobar"
py> s[:3]
py> s[:3] + "B" + s[4:]

Brian Beck
Adventurer of the First Order

More information about the Python-list mailing list