Search⌘ K
AI Features

String Methods

Learn how to use Python string methods to manipulate and analyze text. This lesson helps you understand methods for searching, formatting, and modifying strings, which are essential for handling textual data in Python programming.

We'll cover the following...

Introduction to string methods

Here are some of the string methods available in the string module (in alphabetical order):

  • string.center(int) returns a copy of string centered in a string of length int.

  • string.count(substring) returns the number of non-overlapping occurrences of substring in string.

  • string.endswith(suffix) returns True if string ends with suffix.

  • string.find(substring) returns the index at the beginning of the first occurrence of substring in string, or it returns -1 if not found.

  • string.isalnum() tests whether all characters are alphanumeric (letters or digits). It returns True if all characters are alphanumeric or False ...