String Methods in Python

A string method is a built-in function in Python that we call on a string to perform specific tasks. These methods help us modify, format, search, validate and analyze string data efficiently.

For better understanding, we have grouped these methods into categories based on their functionality.

Categories of String Methods:

  1. Commonly Used Methods — frequently used methods across all tasks.
  2. Case Conversion Methods — to change the case of letters.
  3. Alignment Methods — to align strings with padding.
  4. Search & Count Methods — to find or count substrings.
  5. Validation Methods — to check string properties.
  6. Modification / Replace Methods — to update or clean strings.

1. Commonly Used String Methods

Here is a list of commonly used string methods that are useful in almost every Python program.

  • upper(), lower() — for case formatting
  • strip(), replace() — for cleaning and editing
  • split(), join() — for conversion between string and list
  • find(), count() — for searching
  • startswith(), endswith() — for checks
  • isdigit(), isalpha() — for validation

Click the next page to explore these commonly used methods in detail with examples, outputs and explanations.

2. Case Conversion Methods

These methods are used to change the letter case in a string.

  • upper() → Converts all characters to uppercase.
  • lower() → Converts all characters to lowercase.
  • title() → Capitalizes the first letter of each word.
  • capitalize() → Capitalizes only the first character of the string.
  • swapcase() → Converts uppercase to lowercase and vice versa.

Click the next page to explore Case Conversion methods in detail with examples, outputs and explanations.

3. Alignment Methods

These methods help align a string within a specified width using padding characters.

  • center(width) → Centers the string in a given width.
  • ljust(width) → Left aligns the string in a given width.
  • rjust(width) → Right aligns the string in a given width.
  • zfill(width) → Pads the string on the left with zeros.

Click the next page to explore Alignment methods in detail with examples, outputs and explanations.

4. Search & Count Methods

These methods are used to search for substrings or count occurrences.

  • find(sub) → Returns index of first occurrence; returns -1 if not found.
  • rfind(sub) → Returns last occurrence index.
  • index(sub) → Like find() but raises error if not found.
  • rindex(sub) → Like rfind() but raises error if not found.
  • count(sub) → Returns number of times a substring occurs.

Click the next page to explore Search & Count methods in detail with examples, outputs and explanations.

5. Validation Methods (Checking)

These methods return True or False based on the content of the string.

  • isalpha() → Checks if all characters are alphabetic.
  • isdigit() → Checks if all characters are digits.
  • isalnum() → Checks if all characters are alphanumeric.
  • isspace() → Checks if the string contains only whitespaces.
  • isupper() → Checks if all characters are uppercase.
  • islower() → Checks if all characters are lowercase.
  • istitle() → Checks if the string follows title case.
  • startswith(sub) → Checks if string starts with given substring.
  • endswith(sub) → Checks if string ends with given substring.

Click the next page to explore Validation methods in detail with examples, outputs and explanations.

6. Modification / Replace Methods

These methods are used to modify, clean or replace parts of a string.

  • replace(old, new) → Replaces all occurrences of a substring.
  • strip() → Removes whitespace from both ends.
  • lstrip() → Removes whitespace from the left side.
  • rstrip() → Removes whitespace from the right side.
  • split() → Splits the string into a list.
  • join() → Joins list elements into a single string.

Click the next page to explore Modification methods in detail with examples, outputs and explanations.

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar