7.2.8.3. Token

class Token[source]

It constructs a unique constant that behaves like a string.

Example:

>>> s = Token('string')
>>> s
string
>>> s == 'string'
False
>>> s == Token('string')
False
>>> {s: 1, Token('string'): 1}
{string: 1, string: 1}
>>> s.capitalize()
'String'

Methods

capitalize Return a capitalized version of S, i.e.
casefold Return a version of S suitable for caseless comparisons.
center Return S centered in a string of length width.
count Return the number of non-overlapping occurrences of substring sub in string S[start:end].
encode Encode S using the codec registered for encoding.
endswith Return True if S ends with the specified suffix, False otherwise.
expandtabs Return a copy of S where all tab characters are expanded using spaces.
find Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
format Return a formatted version of S, using substitutions from args and kwargs.
format_map Return a formatted version of S, using substitutions from mapping.
index Like S.find() but raise ValueError when the substring is not found.
isalnum Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.
isalpha Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.
isdecimal Return True if there are only decimal characters in S, False otherwise.
isdigit Return True if all characters in S are digits and there is at least one character in S, False otherwise.
isidentifier Return True if S is a valid identifier according to the language definition.
islower Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.
isnumeric Return True if there are only numeric characters in S, False otherwise.
isprintable Return True if all characters in S are considered printable in repr() or S is empty, False otherwise.
isspace Return True if all characters in S are whitespace and there is at least one character in S, False otherwise.
istitle Return True if S is a titlecased string and there is at least one character in S, i.e.
isupper Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.
join Return a string which is the concatenation of the strings in the iterable.
ljust Return S left-justified in a Unicode string of length width.
lower Return a copy of the string S converted to lowercase.
lstrip Return a copy of the string S with leading whitespace removed.
maketrans Return a translation table usable for str.translate().
partition Search for the separator sep in S, and return the part before it, the separator itself, and the part after it.
replace Return a copy of S with all occurrences of substring old replaced by new.
rfind Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
rindex Like S.rfind() but raise ValueError when the substring is not found.
rjust Return S right-justified in a string of length width.
rpartition Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it.
rsplit Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front.
rstrip Return a copy of the string S with trailing whitespace removed.
split Return a list of the words in S, using sep as the delimiter string.
splitlines Return a list of the lines in S, breaking at line boundaries.
startswith Return True if S starts with the specified prefix, False otherwise.
strip Return a copy of the string S with leading and trailing whitespace removed.
swapcase Return a copy of S with uppercase characters converted to lowercase and vice versa.
title Return a titlecased version of S, i.e.
translate Return a copy of the string S in which each character has been mapped through the given translation table.
upper Return a copy of S converted to uppercase.
zfill Pad a numeric string S with zeros on the left, to fill a field of the specified width.
__init__()

Initialize self. See help(type(self)) for accurate signature.