Skip to content

Computer Science · Ch 8 — Strings

String Operations

8.3

String Operations

Because a string is a sequence of characters, Python allows a set of standard operations to be performed on string values. There are four of them, each with its own operator or notation:

  • Concatenation (Section 8.3.1) — joining two strings end to end with the + operator.
  • Repetition (Section 8.3.2) — repeating a string a given number of times with the * operator.
  • Membership (Section 8.3.3) — testing whether one string occurs inside another with the in and not in operators.
  • Slicing (Section 8.3.4) — extracting a part (substring) of a string by specifying an index range. …