← All notes

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

Sources

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

Permanent ID: iil:note:rmw1qn6n

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.},
}

Markdown

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.

All artifact files (JSON index)

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.