例如,这些在运算符模块中定义,可以这样使用:
import operator
print operator.__add__ # alias add -> +
print operator.__sub__ # alias sub -> -
print operator.__and__ # alias and_ -> &
print operator.__or__ # alias or_ -> |
Run Code Online (Sandbox Code Playgroud)
那么什么是相当于and和or?
print operator."and ?????" # should be boolean-and
print operator."or ????" # should be boolean-or
Run Code Online (Sandbox Code Playgroud)