# Use brackets for string subscripting and substrings.
bozon = 'Cheer for Friday'
# Index at zero.
print(bozon, bozon, bozon)
# You may not use  on the left of an assignment, however.
# Use the colon to describe ranges. The last character is not part of the
print(bozon[0:5] + ", " + bozon[0:6] + bozon[10:16] + '!')
# Defaults to first and last.
print(bozon[:5] + ", " + bozon[:6] + bozon[10:] + '!')
# The * operator repeats strings (like x in perl).
print(bozon[:6] * 3 + '!')
# Negatives index back from the right, the rightmost character being -1.
Lutz and Ascher suggest that you can think of a negative
index, s[-4], as a shorthand
for the equivalent s[len(s)-4].
The [n] operation is called indexing, and the
[n:m] is called slicing. Both operations return a new
string, leaving the original unchanged.
Since python strings are
immutable, you cannot use an index or slice expression on the left
of an assignment.
Note that immutability means you cannot update an existing value, but you
can, of course, change a variable to a new value. For instance:
fred = 'Q'
is illegal, but you can do this instead:
fred = fred + 'Q' + fred[2:]