9.1. Introduction: Transforming Sequences¶
The sequences that we have used so far have been static: a list of colors that doesn’t change or the characters in a string that stays the same. The real world is more complicated than that. A list of users for your social network may need to grow to accommodate new users (or shrink when users leave your service). The letters in a string may need to be modified to personalize a message (“Welcome to Wonderland, <your name>”), or to encode a secret message.
The following chapter will detail more of the methods that can be used to transform lists and strings. Generally, the two methods that can be used are changing the list object, in place, by mutating it; or by constructing a new string object using a copy-with-change operation.
9.1.1. Learning Goals¶
To understand the concepts of mutable and immutable data types
To understand that methods on strings leave the origninal string alone but return a new string
To understand that lists are mutable data types and that mutating methods on lists return None
Demonstrate the correct use of:
search - contains in / not in and index
string format method