The string capitalize method returns a copy of the string with its first character capitalized and the rest converted to lowercase
Reference
String Methods
Methods available on Python str objects.
- str.capitalize()
- str.casefold()
The casefold method returns a casefolded copy of a string, useful for case-insensitive string matching and Unicode-aware lowercase conversion
- str.center()
The string center method returns a centered string of the specified width, padded with a specified fill character
- str.count()
The string count() method returns the number of non-overlapping occurrences of a substring in the string
- str.encode()
The string encode method returns an encoded version of the string as a bytes object, with support for various character encodings
- str.endswith()
The string endswith method returns True if the string ends with the specified suffix, otherwise False
- str.expandtabs()
The expandtabs method returns a copy of the string with tab characters expanded to spaces
- str.find()
Find the index of a substring in a string. Returns -1 if not found.
- str.format_map()
The string format_map method performs string formatting using a mapping object directly without copying it
- str.format()
Format values into strings using replacement fields and format specifiers
- str.isalnum()
The isalnum method returns True if all characters in the string are alphanumeric (letters or digits) and the string is not empty
- str.isalpha()
The isalpha method returns True if all characters in the string are alphabetic letters and the string is not empty
- str.isascii()
The string isascii method returns True if all characters in the string are ASCII, False otherwise
- str.isdecimal()
Check if all characters in a string are decimal characters (under 160 chars)
- str.isdigit()
Check if all characters in a string are digits.
- str.isidentifier()
Check if a string is a valid Python identifier
- str.islower()
The islower method returns True if all cased characters in a string are lowercase and the string contains at least one cased character
- str.isnumeric()
Check if all characters in a string are numeric characters (supports Unicode)
- str.isprintable()
The isprintable method returns True if all characters in the string are printable
- str.isspace()
Returns True if all characters in the string are whitespace characters and the string is not empty.
- str.istitle()
The istitle method returns True if the string is titlecased where each word starts with an uppercase character followed by lowercase letters
- str.isupper()
Returns True if all cased characters in a string are uppercase and there is at least one cased character.
- str.join()
The string join method returns a string by joining iterable elements with a separator
- str.ljust()
The string ljust method returns a left-justified version of the string padded with spaces or a custom character
- str.lower()
The lower method returns a copy of the string with all characters converted to lowercase
- str.lstrip()
Remove leading characters from a string. Defaults to whitespace.
- str.maketrans()
The str.maketrans() method creates a translation table for use with the translate() method
- str.partition()
Split a string into three parts using a separator, returning a 3-tuple.
- str.removeprefix()
Remove a prefix from a string if present. Returns the original string unchanged if the prefix doesn't match.
- str.removesuffix()
Remove a suffix from a string if present. Returns the original string unchanged if the suffix doesn't match.
- str.replace()
Replace substrings in a string with a new value. Supports optional count limit.
- str.rfind()
Find the highest index of a substring in a string. Returns -1 if not found.
- str.rjust()
Right-justify a string in a field of given width.
- str.rpartition()
Split a string from the right into three parts using a separator, returning a 3-tuple.
- str.rsplit()
Split a string from the right into a list of substrings with rsplit().
- str.rstrip()
Remove trailing characters from a string. Defaults to whitespace.
- str.split()
Split a string into a list of substrings with the split() method.
- str.splitlines()
Split a string into a list of lines, handling various line ending styles.
- str.startswith()
Check if a string starts with a given prefix
- str.strip()
Remove leading and trailing characters from a string. Defaults to whitespace.
- str.swapcase()
Returns a string with uppercase characters converted to lowercase and vice versa.
- str.title()
Returns a titlecased version of the string where words start with uppercase characters.
- str.translate()
The translate method returns a copy of the string where each character has been mapped through a translation table
- str.upper()
Converts all characters in a string to uppercase, returning a new string.
- str.zfill()
Pad a string with zeros on the left to reach a desired width.