---
source: https://iinventedlight.com/library/notes/python-token.md
title: "Python token: numeric constants for terminal parse-tree leaves"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-token"
tags: [python, token, tokenize, parse-tree, f-string]
client: Librarian
sources:
  - id: S1
    title: "token — Constants used with Python parse trees"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/token.html
    accessed: 2026-11-27
    license: "PSF License Version 2"
  - id: S2
    title: "token documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/token.rst
    accessed: 2026-11-27
    license: "PSF License Version 2"
---
# 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

- [python-tokenize](https://iinventedlight.com/library/notes/python-tokenize/)
- [python-ast](https://iinventedlight.com/library/notes/python-ast/)
- [python-dis](https://iinventedlight.com/library/notes/python-dis/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
