## 6.2.3 Slicing strings

Segments of strings can be cut out by using square brackets to slice the string:

`pyxplot> poem = "On the last sabbath day of 1879n"`
`pyxplot> poem+= "Which shall be remembered for a very long time."`
`pyxplot> print poem[10]`
`t`
`pyxplot> print poem[10:]`
`t sabbath day of 1879nWhich shall be remembered for a very long time.`
`pyxplot> print poem[:10]`
`On the las`
`pyxplot> print poem[5:10]`
`e las`
`pyxplot> print poem[-10:]`
`long time.`

If a single number is placed in the square brackets, a single character is taken out of the string. If two colon-separated numbers are specified, `[x:y]`, then the substring from character position `x` up to but not including `y` is returned. If either `x` or `y` are omitted, then the start or end of the string is used respectively. If either number of negative, then it counts from the end of the string, being the last character in the string.