3.7. Sequence Methods and Working with Strings and Lists¶
As discussed in the last chapter, all values in Python are objects that comes bundled with any number of associated methods. In this section, we will point out some useful methods for working with sequences.
3.7.1. String Methods¶
We previously saw that each turtle instance has its own attributes and a number
of methods that can be applied to the instance. For example, we wrote
tess.right(90)
when we wanted the turtle object tess
to perform the
right
method to turn to the right 90 degrees. The “dot notation” is the way
we connect the name of an object to the name of a method it can perform.
Strings are also objects. Each string instance has its own attributes and methods. The most important attribute of the string is the collection of characters. There are a wide variety of methods. Consider the following program.
In [1]: ss = "Hello, World"
In [2]: ss.upper()
Out[2]: 'HELLO, WORLD'
In [3]: ss.lower()