`:=`和` |`在文档中

2024-10-02 14:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

Python文档中到处都有::=

例如:

atom      ::=  identifier | literal | enclosure

我搜索并学习了它的BNF语法。你知道吗

从几十个文件中得到一个简短的想法真的不容易。你知道吗

在python中:可以看作是'assignment'符号=的变体

在Django的模板语法中,|是函数符号。你知道吗

BFN中的::=|是什么?你知道吗


Tags: 文件django函数文档模板语法符号变体
2条回答

在适用于许多语言语法的Backus-Naur形式中,::=表示语法的某个元素的定义,几乎像宏一样。根据the Wikipedia page

The "::=" means that the symbol on the left must be replaced with the expression on the right.

假设形式的定义是:

symbol ::= expression

表示出现symbol的地方,替换为expression。你知道吗

|表示“or”,如在atom中定义为标识符、文字或附件。同样,从维基百科页面:

more sequences are separated by the vertical bar "|", indicating a choice, the whole being a possible substitution for the symbol on the left.

因此,当用“|”分隔时,左边的符号可以是左边表达式中的许多符号之一。总之,文档实际上是这样说的:“只要有atom,就意味着那里可能有一个文本、标识符或附件”。你知道吗

wikipedia

The "::=" means that the symbol on the left must be replaced with the expression on the right.

|符号表示独占的OR。你知道吗

这意味着你必须用identifierliteralenclosure来替换atom。你知道吗

相关问题 更多 >