English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Python Functions

Python Data Types

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Knowledge of Python

Python Reference Manual

Python string methods

Python string methods, a string is a sequence of characters enclosed in quotes. On this reference page, you will find all the methods that a string object can call. For example, you can use the join() method to concatenate two strings. Note: All string methods return a new value. They do not change the original string.

MethodDescription
capitalize()Convert the first character to uppercase.
casefold()Convert the string to lowercase.
center()Return a new string that is centered and padded with spaces to the length width of the original string.
count()Return the number of times the specified value appears in the string.
encode()Return the encoding version of the string.
endswith()If the string ends with the specified value, return true.
expandtabs()Set the tab size of the string.
find()Search for the specified value in the string and return the position where it is found.
format()Format the specified value in the string.
format_map()Format the specified value in the string.
index()Search for the specified value in the string and return the position where it is found.
isalnum()If all characters in the string are alphanumeric, return True.
isalpha()If all characters in the string are in the alphabet, return True.
isdecimal()If all characters in the string are decimal numbers, return True.
isdigit()If all characters in the string are digits, return True.
isidentifier()Return True if the string is an identifier.
islower()Return True if all characters in the string are lowercase.
isnumeric()Return True if all characters in the string are numbers.
isprintable()Return True if all characters in the string are printable.
isspace()Return True if all characters in the string are whitespace characters.
istitle()Return True if the string follows the title case rules.
isupper()Return True if all characters in the string are uppercase.
join()Join the elements of an iterable object to the end of the string.
ljust()Return the left-aligned version of the string.
lower()Convert the string to lowercase.
lstrip()Return the left-trimmed version of the string.
maketrans()Return the translation table used in the conversion.
partition()Return a tuple where the string is divided into three parts.
replace()Return a string where the specified value is replaced with the specified value.
rfind()Search for the specified value in the string and return the last position where it is found.
rindex()Search for the specified value in the string and return the last position where it is found.
rjust()Return the right-aligned version of the string.
rpartition()Return a tuple, where the string is divided into three parts.
rsplit()Split the string at the specified delimiter and return a list.
rstrip()Return the right-trimmed version of the string.
split()Split the string at the specified delimiter and return a list.
splitlines()Split the string at newline characters and return a list.
startswith()Return true if the string starts with the specified value.
strip()Return the truncated version of the string.
swapcase()Toggle case, lowercase becomes uppercase and vice versa.
title()Convert the first character of each word to uppercase.
translate()Return the converted string.
upper()Convert the string to uppercase.
zfill()Fill the beginning of the string with the specified number of 0 values.

Note: All string methods return a new value. They do not change the original string.

Please Python String Tutorial Learn more about strings in Chinese.