Reference group
>String Methods
Practical tools for finding, changing, checking, and splitting Python text. 47 entries.
capitalize()str.capitalize()Return a copy with the first character uppercase and the rest lowercase.casefold()str.casefold()Return a very thorough lowercase version for case-insensitive text matching.center()str.center(width, fillchar=' ')Pad both sides so text is centred in a chosen width.count()str.count(sub, start=0, end=len(str))Count how many non-overlapping times some text appears.encode()str.encode(encoding='utf-8', errors='strict')Turn text into bytes using an encoding such as UTF-8.endswith()str.endswith(suffix, start=0, end=len(str))Check whether text ends with a particular suffix.expandtabs()str.expandtabs(tabsize=8)Replace tab characters with spaces up to the next tab stop.find()str.find(sub, start=0, end=len(str))Find the first position of some text without raising an error when it is missing.format()str.format(*args, **kwargs)Fill replacement fields in text with values.format_map()str.format_map(mapping)Fill named replacement fields from one mapping such as a dictionary.index()str.index(sub, start=0, end=len(str))Find the first position of some text and raise an error if it is missing.isalnum()str.isalnum()Check whether every character is a letter or a number.isalpha()str.isalpha()Check whether every character is a letter.isascii()str.isascii()Check whether every character is an ASCII character.isdecimal()str.isdecimal()Check for characters used as base-10 decimal digits.isdigit()str.isdigit()Check whether every character is a digit, including some special digit characters.isidentifier()str.isidentifier()Check whether text can be used as a Python identifier.islower()str.islower()Check whether all cased characters are lowercase.isnumeric()str.isnumeric()Check whether every character has a numeric value.isprintable()str.isprintable()Check whether all characters can be printed, apart from the empty string which also passes.isspace()str.isspace()Check whether every character is whitespace.istitle()str.istitle()Check whether cased words follow title case.isupper()str.isupper()Check whether all cased characters are uppercase.join()str.join(iterable)Join several strings together using this string as the separator.ljust()str.ljust(width, fillchar=' ')Pad the right side so text reaches a chosen width.lower()str.lower()Return a lowercase copy of text.lstrip()str.lstrip(chars=None)Remove whitespace or chosen characters from the left end.maketrans()str.maketrans(x, y=None, z=None)Create a translation table for use with translate().partition()str.partition(sep)Split text once at the first separator and keep the separator in the result.removeprefix()str.removeprefix(prefix, /)Remove one exact prefix if it is present.removesuffix()str.removesuffix(suffix, /)Remove one exact suffix if it is present.replace()str.replace(old, new, count=-1)Replace matching text with new text.rfind()str.rfind(sub, start=0, end=len(str))Find the last position of some text without raising an error when it is missing.rindex()str.rindex(sub, start=0, end=len(str))Find the last position of some text and raise an error if it is missing.rjust()str.rjust(width, fillchar=' ')Pad the left side so text reaches a chosen width.rpartition()str.rpartition(sep)Split text once at the last separator and keep the separator in the result.rsplit()str.rsplit(sep=None, maxsplit=-1)Split text into a list, starting from the right when a limit is used.rstrip()str.rstrip(chars=None)Remove whitespace or chosen characters from the right end.split()str.split(sep=None, maxsplit=-1)Split text into a list of pieces.splitlines()str.splitlines(keepends=False)Split text at line boundaries.startswith()str.startswith(prefix, start=0, end=len(str))Check whether text starts with a particular prefix.strip()str.strip(chars=None)Remove whitespace or chosen characters from both ends.swapcase()str.swapcase()Return a copy with uppercase and lowercase letters swapped.title()str.title()Return a copy with words changed to title case.translate()str.translate(table)Replace or remove characters according to a translation table.upper()str.upper()Return an uppercase copy of text.zfill()str.zfill(width)Pad the left side with zeroes until text reaches a chosen width.
Looking for something else?
All reference groups