Sitemap

String Methods in python

4 min readJun 23, 2026

--

  • upper() : Converts all lowercase letters to UPPERCASE. (Non-alphabets are completely ignored).
  • lower():Converts all uppercase letters to lowercase.
  • title() :Capitalizes the First Letter Of Every Word.
  • capitalize() :Capitalizes only the very first letter of the entire string.
  • swapcase(): Swaps the case (UPPER → lower, and lower →$ UPPER).
  • strip() Cuts out all spaces from both the left (start) and right (end) sides.
  • lstrip() :Cuts out spaces from the Left side only.
  • rstrip() :Cuts out spaces from the Right side only.
  • count(substring) :Counts how many times a character/pattern appears.
  • find(substring) :Returns the lowest index address. Returns -1 if the character is not found.
  • index(substring) :Exactly like find(), but crashes with a ValueError if not found.
  • split(separator): Breaks a single string into a List of multiple strings based on a separator.
  • replace(old, new) :Swaps an old character/pattern with a brand new one.
  • isalpha() :True if it contains only alphabets (No spaces allowed!).
  • isdigit() :True if it contains only numbers (0-9).
  • isalnum() :True if it is a mix of only alphabets and numbers.
  • islower() :True if all letters are lowercase.
  • isupper() :True if all letters are uppercase.

partition(substring)

  • Always cuts the string into exactly 3 parts based on your split value.
  • Layout: (before, split_value, after)

center(len, ch)

  • Shifts the string right to the center of a new line.
  • Layout: Fills left and right sides with your custom character (ch)

zfill(len)

  • Pads your data with leading zeros (0) on the left side.
  • Layout: Stops filling once the total length matches your len number.

str.maketrans("input", "output")

  • Creates a mapping table (dictionary) that connects the ASCII values of your input characters to your output characters.
  • Rule: The input and output strings must have the same length

Var.translate(mapping_table)

  • Uses the mapping table to actually swap out characters in your string.
  • Rule: Can be used on any string to perform character translation

isupper()

  • Checks whether all the characters inside a string are in uppercase.
  • Rule: Returns True if all letters are capital; otherwise False.

. islower()

  • Checks whether all the characters inside a string are in lowercase.

.️⃣ istitle()

  • Checks every single word in the string.
  • Rule: Returns True if the 1st letter of every word is uppercase and the remaining letters are lowercase.

Get Vinod Gosala’s stories in your inbox

Join Medium for free to get updates from this writer.

. isdigit()

  • Returns True if all the elements in the string are numbers (0-9). Otherwise, returns False.

. isalpha()

  • Returns True if all the elements in the string are alphabets (a-z, A-Z). (No spaces or numbers allowed!)

. isalnum()

  • Returns True if the string contains a clean mix of only alphabets, only digits, or both (no special characters like @, #, or spaces).

isspace()

  • Checks if the string contains only whitespace characters (spaces, tabs, or newlines).
  • Output: Returns True if it is completely empty space; otherwise False.

. isidentifier()

  • Checks whether a string can be used as a valid Variable Name / Identifier according to Python’s naming conventions.
  • Rule: Returns True if it only contains letters, numbers, and underscores, and does not start with a number.

. startswith(substring)

  • Checks if a string sequence begins with a specific character or phrase.
  • Output: Returns True if the prefix matches; otherwise False.

. endswith(substring)

  • Checks if a string sequence finishes with a specific character or phrase.
  • Output: Returns True if the suffix matches; otherwise False

isspace()

  • In Short: Checks if the string contains only whitespace characters (spaces, tabs, or newlines).
  • Output: Returns True if it is completely empty space; otherwise False.

. isidentifier()

  • Checks whether a string can be used as a valid Variable Name / Identifier according to Python’s naming conventions.
  • Rule: Returns True if it only contains letters, numbers, and underscores, and does not start with a number.

. startswith(substring)

  • Checks if a string sequence begins with a specific character or phrase.
  • Output: Returns True if the prefix matches; otherwise False.

. endswith(substring)

  • Checks if a string sequence finishes with a specific character or phrase.
  • Output: Returns True if the suffix matches; otherwise False

. isspace()

  • Checks if the string contains only whitespace characters (spaces, tabs, or newlines).
  • Output: Returns True if it is completely empty space; otherwise False.

. isidentifier()

  • Checks whether a string can be used as a valid Variable Name / Identifier according to Python’s naming conventions.
  • Rule: Returns True if it only contains letters, numbers, and underscores, and does not start with a number.

. startswith(substring)

  • Checks if a string sequence begins with a specific character or phrase.
  • Output: Returns True if the prefix matches; otherwise False.

. endswith(substring)

  • Checks if a string sequence finishes with a specific character or phrase.
  • Output: Returns True if the suffix matches; otherwise False.

--

--