Python token: numeric constants for terminal parse-tree leaves
Answer: The token module holds numeric constants for terminal (leaf) nodes of a Python parse tree, plus helpers that name and classify those values.
Constants and helpers
Constants in this module represent numeric values for parse-tree leaf nodes, the terminal tokens. Grammar/Tokens in the Python distribution defines the names. Those numbers may change from one Python version to another.
tok_name maps those numeric values back to name strings for a readable parse tree.
ISTERMINAL, ISNONTERMINAL, and ISEOF classify terminal values, non-terminal values, and the end-of-input marker. They mirror the Python C header files.
A token's reported value can depend on tokenizer options. For example, a + token may appear as PLUS or OP, and a match token may appear as NAME or SOFT_KEYWORD.
Common token kinds
NAME marks an identifier or keyword. NUMBER marks a numeric literal. STRING marks a string or byte literal, but not formatted string literals. The token string is not interpreted. It includes surrounding quotation marks and the prefix. Backslashes are included literally.
OP is a generic operator or delimiter value reported by the tokenize module.
COMMENT marks a comment and is ignored by the parser. NEWLINE ends a logical line. NL marks a non-terminating newline, which the parser also ignores.
INDENT and DEDENT appear at the start of a logical line to open or close an indented block.
FSTRING_START indicates the beginning of an f-string literal. FSTRING_MIDDLE is literal text inside an f-string. FSTRING_END indicates the end of an f-string. TSTRING_START was added in version 3.14 for template string literals.
See also
Claims
- id: C1 claim: The module's constants represent numeric values of terminal parse-tree leaves. source: S1 evidence: "numeric values of leaf nodes"
- id: C2 claim: tok_name maps those numeric values back to name strings. source: S2 evidence: "Dictionary mapping the numeric values of the constants"
- id: C3 claim: The value reported for a token can depend on tokenizer options. source: S2 evidence: "a token's value may depend on tokenizer options"
Sources
- [S1] token — Constants used with Python parse trees. Python Software Foundation. https://docs.python.org/3/library/token.html . License: PSF License Version 2. Accessed 2026-11-27.
- [S2] token documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/token.rst . License: PSF License Version 2. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, token — Constants used with Python parse trees; CPython, token documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, token — Constants used with Python parse trees; CPython, token documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python token: numeric constants for terminal parse-tree leaves." iinventedlight Library, iil:note:rmw1qn6n, version of 2026-11-27. https://iinventedlight.com/library/notes/python-token/. License: CC-BY-4.0.
@misc{iil_note_rmw1qn6n,
author = {{iinventedlight}},
title = {{Python token: numeric constants for terminal parse-tree leaves}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/python-token/},
note = {Permanent ID iil:note:rmw1qn6n. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-token.schema.json (schema; CC-BY-4.0)
- python-token.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-token.md.