Strings as sequences

The Strings in Python are what are called sequence types, which means they support certain common operations for querying ordered series of elements. For example, we can access individual characters using square brackets with an zero-based integer index:

>>> s = 'parrot'
>>> s[4]
'o'

In contrast to many other programming languages, there is no separate character type distinct from the string type. The indexing operation returns a full-blown string that just contains a single code point element, a fact we can demonstrate using Python's built-in type() function:

>>> type(s[4])
<class 'str'>

We'll be looking at types and classes much more later in this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset