str
def str(a, /) -> str
str: formats its argument as a string.
If x is a string, the result is x (without quotation). All other strings, such as elements of a list of strings, are double-quoted.
str(1) == '1'
str("x") == 'x'
str([1, "x"]) == "[1, \"x\"]"
str.capitalize
def str.capitalize() -> str
string.capitalize: returns a copy of string S, where the first character (if any) is converted to uppercase; all other characters are converted to lowercase.
"hello, world!".capitalize() == "Hello, world!"
"Hello, World!".capitalize() == "Hello, world!"
"".capitalize() == ""
str.codepoints
def str.codepoints(
) -> typing.Iterable[int]
string.codepoints: returns an iterable of the unicode codepoint of a string.
S.codepoints() returns an iterable value containing the
sequence of integer Unicode code points encoded by the string S.
Each invalid code within the string is treated as if it encodes the
Unicode replacement character, U+FFFD.
By returning an iterable, not a list, the cost of decoding the string
is deferred until actually needed; apply list(...) to the result to
materialize the entire sequence.
list("Hello, 世界".codepoints()) == [72, 101, 108, 108, 111, 44, 32, 19990, 30028]
str.count
def str.count(
needle: str,
start: None | int = None,
end: None | int = None,
/,
) -> int
string.count: count the number of occurrences of a string in another string.
S.count(sub[, start[, end]]) returns the number of occurrences of
sub within the string S, or, if the optional substring indices
start and end are provided, within the designated substring of S.
They are interpreted according to Skylark's indexing conventions.
This implementation does not count occurrence of sub in the string S
that overlap other occurrence of S (which can happen if some suffix of S
is a prefix of S). For instance, "abababa".count("aba") returns 2
for [aba]a[aba], not counting the middle occurrence: ab[aba]ba
(this is following Python behavior).
"hello, world!".count("o") == 2
"abababa".count("aba") == 2
"hello, world!".count("o", 7, 12) == 1 # in "world"
str.elems
def str.elems() -> typing.Iterable[str]
string.elems: returns an iterable of the bytes values of a string.
S.elems() returns an iterable value containing the
sequence of numeric bytes values in the string S.
To materialize the entire sequence of bytes, apply list(...) to the
result.
list("Hello, 世界".elems()) == ["H", "e", "l", "l", "o", ",", " ", "世", "界"]
str.endswith
def str.endswith(
suffix: str | tuple[str, ...],
start: None | int = None,
end: None | int = None,
/,
) -> bool
string.endswith: determine if a string ends with a given suffix.
S.endswith(suffix[, start[, end]]) reports whether the string
S[start:end] has the specified suffix.
"filename.sky".endswith(".sky") == True
"hello".endswith("ell", 0, 4) == True
"hello".endswith("lo", 3) == True
str.find
def str.find(
needle: str,
start: None | int = None,
end: None | int = None,
/,
) -> int
string.find: find a substring in a string.
S.find(sub[, start[, end]]) returns the index of the first
occurrence of the substring sub within S.
If either or both of start or end are specified,
they specify a subrange of S to which the search should be restricted.
They are interpreted according to Skylark's indexing
conventions.
If no occurrence is found, found returns -1.
"bonbon".find("on") == 1
"bonbon".find("on", 2) == 4
"bonbon".find("on", 2, 5) == -1
str.format
def str.format(
*args,
**kwargs,
) -> str
string.format: format a string.
S.format(*args, **kwargs) returns a version of the format string S
in which bracketed portions {...} are replaced
by arguments from args and kwargs.
Within the format string, a pair of braces {{ or }} is treated as
a literal open or close brace.
Each unpaired open brace must be matched by a close brace }.
The optional text between corresponding open and close braces
specifies which argument to use and how to format it, and consists of
three components, all optional:
a field name, a conversion preceded by '!', and a format specifier
preceded by ':'.
{field}
{field:spec}
{field!conv}
{field!conv:spec}
The field name may be either a decimal number or a keyword. A number is interpreted as the index of a positional argument; a keyword specifies the value of a keyword argument. If all the numeric field names form the sequence 0, 1, 2, and so on, they may be omitted and those values will be implied; however, the explicit and implicit forms may not be mixed.
The conversion specifies how to convert an argument value x to a
string. It may be either !r, which converts the value using
repr(x), or !s, which converts the value using str(x) and is
the default.
The format specifier, after a colon, specifies field width, alignment, padding, and numeric precision. Currently it must be empty, but it is reserved for future use.
"a {} c".format(3) == "a 3 c"
"a{x}b{y}c{}".format(1, x=2, y=3) == "a2b3c1"
"a{}b{}c".format(1, 2) == "a1b2c"
"({1}, {0})".format("zero", "one") == "(one, zero)"
"Is {0!r} {0!s}?".format("heterological") == "Is \"heterological\" heterological?"
str.index
def str.index(
needle: str,
start: None | int = None,
end: None | int = None,
/,
) -> int
string.index: search a substring inside a string, failing on not found.
S.index(sub[, start[, end]]) returns the index of the first
occurrence of the substring sub within S, like S.find, except
that if the substring is not found, the operation fails.
"bonbon".index("on") == 1
"bonbon".index("on", 2) == 4
"bonbon".index("on", 2, 5) # error: not found
str.isalnum
def str.isalnum() -> bool
string.isalnum: test if a string is composed only of letters and digits.
S.isalnum() reports whether the string S is non-empty and consists
only Unicode letters and digits.
"base64".isalnum() == True
"Catch-22".isalnum() == False
str.isalpha
def str.isalpha() -> bool
string.isalpha: test if a string is composed only of letters.
S.isalpha() reports whether the string S is non-empty and consists
only of Unicode letters.
"ABC".isalpha() == True
"Catch-22".isalpha() == False
"".isalpha() == False
str.isdigit
def str.isdigit() -> bool
string.isdigit: test if a string is composed only of digits.
S.isdigit() reports whether the string S is non-empty and consists
only of Unicode digits.
"123".isdigit() == True
"Catch-22".isdigit() == False
"".isdigit() == False
str.islower
def str.islower() -> bool
string.islower: test if all letters of a string are lowercase.
S.islower() reports whether the string S contains at least one cased
Unicode letter, and all such letters are lowercase.
"hello, world".islower() == True
"Catch-22".islower() == False
"123".islower() == False
str.isspace
def str.isspace() -> bool
string.isspace: test if all characters of a string are whitespaces.
S.isspace() reports whether the string S is non-empty and consists
only of Unicode spaces.
" ".isspace() == True
"\r\t\n".isspace() == True
"".isspace() == False