On this page
typing.Text
Prev: typing.SupportsRound | Up: typing | Next: typing.TextIO
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.Text
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import Text
Signature & Overview
typing.Text(...)
str(bytes_or_buffer[, encoding[, errors]]) -> str Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer
Methods & Attributes
Text.capitalize(self, /)— Return a capitalized version of the string.Text.casefold(self, /)— Return a version of the string suitable for caseless comparisons.Text.center(self, width, fillchar=' ', /)— Return a centered string of length width.Text.count(...)— Return the number of non-overlapping occurrences of substring sub in string S[start:end].Text.encode(self, /, encoding='utf-8', errors='strict')— Encode the string using the codec registered for encoding.Text.endswith(...)— Return True if the string ends with the specified suffix, False otherwise.Text.expandtabs(self, /, tabsize=8)— Return a copy where all tab characters are expanded using spaces.Text.find(...)— Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].Text.format(self, /, *args, **kwargs)— Return a formatted version of the string, using substitutions from args and kwargs.Text.format_map(self, mapping, /)— Return a formatted version of the string, using substitutions from mapping.Text.index(...)— Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].Text.isalnum(self, /)— Return True if the string is an alpha-numeric string, False otherwise.Text.isalpha(self, /)— Return True if the string is an alphabetic string, False otherwise.Text.isascii(self, /)— Return True if all characters in the string are ASCII, False otherwise.Text.isdecimal(self, /)— Return True if the string is a decimal string, False otherwise.Text.isdigit(self, /)— Return True if the string is a digit string, False otherwise.Text.isidentifier(self, /)— Return True if the string is a valid Python identifier, False otherwise.Text.islower(self, /)— Return True if the string is a lowercase string, False otherwise.Text.isnumeric(self, /)— Return True if the string is a numeric string, False otherwise.Text.isprintable(self, /)— Return True if all characters in the string are printable, False otherwise.Text.isspace(self, /)— Return True if the string is a whitespace string, False otherwise.Text.istitle(self, /)— Return True if the string is a title-cased string, False otherwise.Text.isupper(self, /)— Return True if the string is an uppercase string, False otherwise.Text.join(self, iterable, /)— Concatenate any number of strings.Text.ljust(self, width, fillchar=' ', /)— Return a left-justified string of length width.Text.lower(self, /)— Return a copy of the string converted to lowercase.Text.lstrip(self, chars=None, /)— Return a copy of the string with leading whitespace removed.Text.maketrans(...)— Return a translation table usable for str.translate().Text.partition(self, sep, /)— Partition the string into three parts using the given separator.Text.removeprefix(self, prefix, /)— Return a str with the given prefix string removed if present.Text.removesuffix(self, suffix, /)— Return a str with the given suffix string removed if present.Text.replace(self, old, new, /, count=-1)— Return a copy with all occurrences of substring old replaced by new.Text.rfind(...)— Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].Text.rindex(...)— Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].Text.rjust(self, width, fillchar=' ', /)— Return a right-justified string of length width.Text.rpartition(self, sep, /)— Partition the string into three parts using the given separator.Text.rsplit(self, /, sep=None, maxsplit=-1)— Return a list of the substrings in the string, using sep as the separator string.Text.rstrip(self, chars=None, /)— Return a copy of the string with trailing whitespace removed.Text.split(self, /, sep=None, maxsplit=-1)— Return a list of the substrings in the string, using sep as the separator string.Text.splitlines(self, /, keepends=False)— Return a list of the lines in the string, breaking at line boundaries.
Usage
from typing import Text
assert Text is str
Gotchas
- Legacy Python 2/3 migration alias: Always use
strdirectly in Python 3.
REPL Inspect
from typing import Text
help(Text)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/SupportsRound Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/TextIO Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing