gpt4 book ai didi

python 语法: wrong atom definition?

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:37 25 4
gpt4 key购买 nike

official documentation 检查 python 语法时, 这是它的内容

atom_expr: ['await'] atom trailer*
atom: ('(' [yield_expr|testlist_comp] ')' |
'[' [testlist_comp] ']' |
'{' [dictorsetmaker] '}' |
NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME

然后,10.bit_length() 是根据该定义但不是根据 python 解释器的有效语法。相反,n=10;n.bit_length() 是规范和解释器的有效语法。

我应该在哪里找到 atomatom_expr真实定义?

最佳答案

感谢juanpa的评论和相关问题的回答,看来问题出在10.。 NUMBER 的定义包括点,这样 10.bit_length() 属于 NUMBER NAME trailer 而不是 NUMBER '.'名称预告片

为了获得 atom_expr,必须将点分开:10.bit_length()(10).bit_length() 都给出正确答案。

关于 python 语法: wrong atom definition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48924608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com