What does this use of << mean in Python

前端 未结 1 1738
不知归路
不知归路 2021-01-22 10:59

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

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

相关标签:
1条回答
  • 2021-01-22 11:46

    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.

    0 讨论(0)
提交回复
热议问题