What does this use of << mean in Python

大兔子大兔子 提交于 2019-12-02 02:14:07

问题


I ran across this use of '<<' in a Python example using the pyparsing module:

whereExpression << whereCondition + ZeroOrMore( ( and_ | or_ ) + whereExpression )

It clearly isn't a binary left shift operator, but I don't find it described in any Python reference. Can someone explain it? Thank you.


回答1:


Like any operator, << can be overloaded by classes to define their own behavior. The example you give looks like it's from code using pyparsing. This is a parser library that overloads operators in this way. The << here updates the content of a previously-defined placeholder token. Read the documentation on pyparsing for more about how this works.

The bottom line is that << can mean anything, just like + or < can mean anything, because the behavior of operators is determined by the types of the objects they operate on. You have to know the types of the objects to understand the behavior.



来源:https://stackoverflow.com/questions/23074266/what-does-this-use-of-mean-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!