A string (e.g. “Hello”) is a collection of characters (unlike a boolean, an integer or a float which are scalar value). In Chapter 7 of the book, we will use strings to build progressively more complex (and more interesting) programs.
Like in Java, strings in python are immutable to increase performance and decrease space requirements.
It is important to understand the following aspects of Strings:
- The len() function
- Traversal using an index and a for loop
- The in and not in operators
- The Python string module
String formatting is an advanced topic and is not essential at this point.
Work out all the examples in the book (except those pertaining to string formatting which can be skipped on a first reading). When you have understood everything, work out the two exercises in section 7.14.
Comment on the power of doctest and slices. For those who have prior exposure to other programming languages, what do you think of Python’s way of managing string?
Work out exercises 1, 2, 5, 6 and 8 in section 7.16. How do you find is_palindrome? What about remove_all?
A lot of people say that modern programming languages like Python allow programmers to program elegantly. Do you think so?
Leave a Reply