Unit B Reading assignment

Chapter 5 Text Strings

Remember that strings are immutable.
Things that appear to make changes do not change the string, but return the modified string.

Create with Quotes

Create with str()

Escape with \

Combine by using +

Duplicate with *

Get a Character with []

This actually extracts a string containing only one character.

Get a Substring with a Slice

Get Length with len()

Split with split()

Combine by using join()

Substitute by using replace()

Strip with strip()

Search and Select

Case

Alignment

Formatting

Old style: %

Do NOT use old style formatting.

New style{} and format()

Newest style: f-strings

f-string is similar to new style formatting, but with different punctuation. f-string is recommended

More String Things

Coming Up

Things to Do

skip; we will have our own exercises and assignments.

Appendix E - Cheat Sheets

Operator Precedence

String Methods

Change Case

Search

Modify

Format

String Type

The Python documentation has a complete listing and explanation of all the string methods, including such additional methods as endswith() and islower(). See: string methods

Chapter 11 Modules, Packages, and Goodies

Modules and the import Statement

Import a Module

Read the last paragraph first. If you write your program this way, it simplify things.

We will import modules from the standard library, but will not build will not build our own modules.
What you will write will be similar to the code in the weatherman.py main program. Look at how weatherman.py uses the report.py module, but not at how to implement a module.

Import a Module with Another Name

omit

Import Only What You Want from a Module

scan

Packages

omit

Goodies in the Python Standard Library

We will use only a few things from the Python Standard Library, but the next course, CIS 41B, will use the Python Standard Library very much.

Handle Missing Keys with setdefault() and defaultDict()

omit for now. We will do this later.

Count Items with Counter()

omit

Order by Key with OrderedDict()

omit

Stack + Queue == deque

omit

Iterate over Code Structures with itertools

omit

Print Nicely with pprint()

omit

Get Random

omit

More Batteries: Get Other Python Code

scan

Coming Up

Things to Do

omit