String Methods

Learn about the different string methods available in Python.

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