Python String Methods

Python has a set of built-in methods that you can use on strings.

Learn more about string in Python String Tutorial.

Python String Methods
capitalize()Capitalizes first character of the string
casefold()Returns a casefolded string
center()Returns center-aligned string
count()Counts occurrences of a substring in a string
encode()Return an encoded version of the string as a bytes object
endswith()Determines whether the string ends with a given suffix
expandtabs()Replaces tabs with spaces
find()Searches the string for a given substring
format()Perform a string formatting operation
format_map()Perform a string formatting operation
index()Searches the string for a given substring
isalnum()Determines whether the string contains alphanumeric characters
isalpha()Determines whether the string contains alphabetic characters
isdecimal()Determines whether the string contains decimal characters
isdigit()Determines whether the string contains digits
isidentifier()Determines whether the string is a valid Python identifier
islower()Determines whether string contains lowercase characters
isnumeric()Determines whether the string contains numeric characters
isprintable()Determines whether string contains printable characters
isspace()Determines whether the string contains only whitespace characters
istitle()Determines whether the string is a titlecased string
isupper()Determines whether string contains uppercase characters
join()Joins all items in an iterable into a single string
ljust()Returns left-aligned string
lower()Converts all characters in a string to lowercase
lstrip()Strips characters from the left end of a string
maketrans()Returns a translation table to be used in translations
partition()Divides a string based on a separator
replace()Replaces occurrences of a substring within a string
rfind()Searches the string for a given substring
rindex()Searches the string for a given substring
rjust()Returns right-aligned string
rpartition()Divides a string based on a separator
rsplit()Splits a string into a list of substrings
rstrip()Strips characters from the right end of a string
split()Splits a string into a list of substrings
splitlines()Splits the string at line breaks
startswith()Determines whether the string starts with a given substring
strip()Strips leading and trailing characters
swapcase()Swaps case of all characters in a string
title()Converts string to “Title Case”
translate()Returns a translated string
upper()Converts all characters in a string to uppercase
zfill()Pads a string on the left with zeros