Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

8.6: Chapter Summary

( \newcommand{\kernel}{\mathrm{null}\,}\)

Highlights from this chapter include:

  • A string is a sequence of characters.
  • Logical operators can be used to compare two string values. String comparison is done by comparing corresponding ASCII values of characters in the order of appearance in the string.
  • String indexing is used to access a character or a sequence of characters in the string.
  • String objects are immutable.
  • String splicing.

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

Method Description

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.
Operator Description

in

Checks if a substring exists in a string.

in operator in a for loop

    for character in string:
      # loop body
Table 8.4 Chapter 8 reference.

This page titled 8.6: Chapter Summary is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by OpenStax via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?