A string is a sequence of characters (an ordered collection of characters), and is delimited by paired single or double quotes, e.g. "This is a string." It is a new type (str) for us. In this section, you will learn about the string data structure and how to work with it. In particular you will learn indexing and iteration.
Chapter 4: Stings
A string is a sequence of characters and is delimited by quotes.
a_string[i], indexing starts at 0, negative indexing starts from end.
a_string[x:y], a slice from index x up to but not including index y.
a_string[x:y:z], a slice from index x up to but not including index y with step z.
Defaults: no x, start slice at beginning; no y, end slice at end.
Idiom: a_string[::-1] is the reverse of a_string.
List of string methods
String Formatting Tutorial
for item in collection: suite-of-statements
We use uppercase characters to SHOUT when typing text. Let's write a program that converts every lowercase character to an uppercase character.
A palindrome is a string that is the same forwards and backwards. Case is ignored as are non-alphabetic and non-numeric characters. For example, "Madam, I'm Adam" is a palindrome.
How to build a string:
a_str = '' # start with an empty string for ch in collection: a_str += ch # add characters to string