Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

8.6 Chapter summary

Highlights from this chapter include:

At this point, you should be able to write programs dealing with string values.

Table 8.4 Chapter 8 reference.
MethodDescription
len()Returns the string length.
upper()Returns uppercase characters.
lower()Returns lowercase characters.
count()Returns the number of a given substring in a string.
find()Returns the index of the first occurrence of a given substring in a string. If the substring does not exist in the string, -1 is returned.
index()Returns the index of the first occurrence of a given substring in a string. If the substring does not exist in the string, a ValueError is returned.
format()Used to create strings with specified patterns using arguments.
join()Takes a list of string values and combines string values into one string by placing a given separator between values.
split()Separates a string into tokens based on a given separator string. If no separator string is provided, blank space characters are used as separators.
OperatorDescription
inChecks if a substring exists in a string.
in operator in a for loop for character in string:   # loop body

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or any other accessibility standard. Every page is built against an automated accessibility gate, and our target for the published editions is WCAG 2.2 Level AA. If something is unusable, please tell us.