Python Language String Methods

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • str.capitalize() -> str
  • str.casefold() -> str [only for Python > 3.3]
  • str.center(width[, fillchar]) -> str
  • str.count(sub[, start[, end]]) -> int
  • str.decode(encoding="utf-8"[, errors]) -> unicode [only in Python 2.x]
  • str.encode(encoding="utf-8", errors="strict") -> bytes
  • str.endswith(suffix[, start[, end]]) -> bool
  • str.expandtabs(tabsize=8) -> str
  • str.find(sub[, start[, end]]) -> int
  • str.format(*args, **kwargs) -> str
  • str.format_map(mapping) -> str
  • str.index(sub[, start[, end]]) -> int
  • str.isalnum() -> bool
  • str.isalpha() -> bool
  • str.isdecimal() -> bool
  • str.isdigit() -> bool
  • str.isidentifier() -> bool
  • str.islower() -> bool
  • str.isnumeric() -> bool
  • str.isprintable() -> bool
  • str.isspace() -> bool
  • str.istitle() -> bool
  • str.isupper() -> bool
  • str.join(iterable) -> str
  • str.ljust(width[, fillchar]) -> str
  • str.lower() -> str
  • str.lstrip([chars]) -> str
  • static str.maketrans(x[, y[, z]])
  • str.partition(sep) -> (head, sep, tail)
  • str.replace(old, new[, count]) -> str
  • str.rfind(sub[, start[, end]]) -> int
  • str.rindex(sub[, start[, end]]) -> int
  • str.rjust(width[, fillchar]) -> str
  • str.rpartition(sep) -> (head, sep, tail)
  • str.rsplit(sep=None, maxsplit=-1) -> list of strings
  • str.rstrip([chars]) -> str
  • str.split(sep=None, maxsplit=-1) -> list of strings
  • str.splitlines([keepends]) -> list of strings
  • str.startswith(prefix[, start[, end]]) -> book
  • str.strip([chars]) -> str
  • str.swapcase() -> str
  • str.title() -> str
  • str.translate(table) -> str
  • str.upper() -> str
  • str.zfill(width) -> str

Remarks

String objects are immutable, meaning that they can't be modified in place the way a list can. Because of this, methods on the built-in type str always return a new str object, which contains the result of the method call.



Got any Python Language Question?