token — Constants used with Python parse trees¶
Source code:Lib/token.py
This module provides constants which represent the numeric values of leaf nodesof the parse tree (terminal tokens). Refer to the fileGrammar/Grammarin the Python distribution for the definitions of the names in the context ofthe language grammar. The specific numeric values which the names map to maychange between Python versions.
The module also provides a mapping from numeric codes to names and somefunctions. The functions mirror definitions in the Python C header files.
token.tok_name¶Dictionary mapping the numeric values of the constants defined in this moduleback to name strings, allowing more human-readable representation of parse treesto be generated.
token.ISTERMINAL(x)¶Return
Truefor terminal token values.
token.ISNONTERMINAL(x)¶Return
Truefor non-terminal token values.
token.ISEOF(x)¶Return
Trueifx is the marker indicating the end of input.
The token constants are:
token.ENDMARKER¶
token.NAME¶
token.NUMBER¶
token.STRING¶
token.NEWLINE¶
token.INDENT¶
token.DEDENT¶
token.LPAR¶Token value for
"(".
token.RPAR¶Token value for
")".
token.LSQB¶Token value for
"[".
token.RSQB¶Token value for
"]".
token.COLON¶Token value for
":".
token.COMMA¶Token value for
",".
token.SEMI¶Token value for
";".
token.PLUS¶Token value for
"+".
token.MINUS¶Token value for
"-".
token.STAR¶Token value for
"*".
token.SLASH¶Token value for
"/".
token.VBAR¶Token value for
"|".
token.AMPER¶Token value for
"&".
token.LESS¶Token value for
"<".
token.GREATER¶Token value for
">".
token.EQUAL¶Token value for
"=".
token.DOT¶Token value for
".".
token.PERCENT¶Token value for
"%".
token.LBRACE¶Token value for
"{".
token.RBRACE¶Token value for
"}".
token.EQEQUAL¶Token value for
"==".
token.NOTEQUAL¶Token value for
"!=".
token.LESSEQUAL¶Token value for
"<=".
token.GREATEREQUAL¶Token value for
">=".
token.TILDE¶Token value for
"~".
token.CIRCUMFLEX¶Token value for
"^".
token.LEFTSHIFT¶Token value for
"<<".
token.RIGHTSHIFT¶Token value for
">>".
token.DOUBLESTAR¶Token value for
"**".
token.PLUSEQUAL¶Token value for
"+=".
token.MINEQUAL¶Token value for
"-=".
token.STAREQUAL¶Token value for
"*=".
token.SLASHEQUAL¶Token value for
"/=".
token.PERCENTEQUAL¶Token value for
"%=".
token.AMPEREQUAL¶Token value for
"&=".
token.VBAREQUAL¶Token value for
"|=".
token.CIRCUMFLEXEQUAL¶Token value for
"^=".
token.LEFTSHIFTEQUAL¶Token value for
"<<=".
token.RIGHTSHIFTEQUAL¶Token value for
">>=".
token.DOUBLESTAREQUAL¶Token value for
"**=".
token.DOUBLESLASH¶Token value for
"//".
token.DOUBLESLASHEQUAL¶Token value for
"//=".
token.AT¶Token value for
"@".
token.ATEQUAL¶Token value for
"@=".
token.RARROW¶Token value for
"->".
token.ELLIPSIS¶Token value for
"...".
token.COLONEQUAL¶Token value for
":=".
token.OP¶
token.AWAIT¶
token.ASYNC¶
token.TYPE_IGNORE¶
token.TYPE_COMMENT¶
token.ERRORTOKEN¶
token.N_TOKENS¶
token.NT_OFFSET¶
The following token type values aren’t used by the C tokenizer but are needed forthetokenize module.
token.COMMENT¶Token value used to indicate a comment.
token.NL¶Token value used to indicate a non-terminating newline. The
NEWLINEtoken indicates the end of a logical line of Python code;NLtokens are generated when a logical line of code is continued overmultiple physical lines.
token.ENCODING¶Token value that indicates the encoding used to decode the source bytesinto text. The first token returned by
tokenize.tokenize()willalways be anENCODINGtoken.
token.TYPE_COMMENTToken value indicating that a type comment was recognized. Suchtokens are only produced when
ast.parse()is invoked withtype_comments=True.
Changed in version 3.7:RemovedAWAIT andASYNC tokens. “async” and “await” arenow tokenized asNAME tokens.
Changed in version 3.8:AddedTYPE_COMMENT,TYPE_IGNORE,COLONEQUAL.AddedAWAIT andASYNC tokens back (they’re neededto support parsing older Python versions forast.parse() withfeature_version set to 6 or lower).