Strings are sequences of characters.
Applications often must process strings.
String manipulation is a common programming task.
Since strings are sequences of characters the storage required will depend on the length of the string.
Most programming languages allow the programmer to ignore the lower-level details of strings.
Question: Given a string value cow, how can it be changed to wow?
A: In general there are two ways:
- Result: Make a copy of the given string that has the required change (and return the copy).
- Side effect: Change the character(s) in the given string.
Note that with the side effect approach the given value is changed (and thus gone).
Python has immutable string values (as do other programming languages).
Since strings are immutable in Python the side effect approach is not applicable.
Strings as Containers
A string has much in common with a list, both store a sequence of values.
A list is a sequence of objects.
A string is a sequence of characters.
A string, like list, may:
- Be subscripted
- Have the len function applied to it