Updated on 2025-09-07 GMT+08:00

Overview

This section describes string functions, including their syntax, parameters, and usage examples.

Function List

Type

Function

Description

Multi-string operations

str_format

Formats a string in a specified format.

str_join

Generates a new string by connecting the input strings using a connector.

str_zip

Splits the strings of two values or expressions concurrently and then combines them into one string.

Sorting, inversion, and replacement

str_sort

Sorts strings.

str_reverse

Reverses a string.

str_replace

Replaces an old string with a new string according to rules.

str_translate

Replaces specified characters in a string based on the mapping.

Common operations

str_strip

Deletes specified characters from a string.

str_lstrip

Deletes specified characters at the beginning of a string.

str_rstrip

Deletes specified characters at the end of a string.

str_lower

Converts all uppercase characters in a string to lowercase characters.

str_upper

Converts all lowercase characters in a string to uppercase characters.

str_title

Converts the first letter of each word in a string to uppercase and the other letters to lowercase.

str_capitalize

Converts the first letter of a string to uppercase and the other letters to lowercase.

str_swapcase

Converts the uppercase and lowercase letters of a string.

Search and judgment

str_count

Calculates the number of occurrences of a character in a string.

str_find

Checks whether the original string contains the specified substring.

str_rfind

Searches for the last occurrence of specified characters a string.

str_endswith

Checks whether a string ends with a specified suffix.

str_startswith

Checks whether a string starts with specified characters.

Splitting

str_split

Splits a string by specifying delimiters.

str_splitlines

Splits a string by specifying newline characters.

str_partition

Splits a string into three parts from left to right based on the specified delimiters.

str_rpartition

Splits a string into three parts from right to left based on the specified delimiters.

Format

str_center

Expands a string to a specified length with specified characters.

str_ljust

Expands a string to a specified length with specified characters starting from the end of the string.

str_rjust

Expands a string to a specified length with specified characters starting from the beginning of the string.

str_zfill

Expands a string to a specified length with the character 0 starting from the beginning of the string.

str_expandtabs

Converts \t in a string to a space.

Character set check

str_isalnum

Checks whether a string consists of only letters and digits.

str_isalpha

Checks whether a string consists of only letters.

str_isascii

Validates whether a string contains only ASCII characters.

str_isdecimal

Checks whether a string consists of only decimal characters.

str_isdigit

Checks whether a string consists of only digits.

str_isidentifier

Checks whether a string is a valid Python identifier.

str_islower

Checks whether a string consists of only lowercase letters.

str_isnumeric

Checks whether a string consists of only digits.

str_isprintable

Checks whether all characters in a string are printable characters.

str_isspace

Checks whether a string consists of only space characters.

str_istitle

Checks whether the first letter of each word in a string is uppercase and whether other letters are lowercase.

str_isupper

Checks whether all letters in a string are uppercase.

str_uuid

Randomly generates a UUID.