Macaulay2 » Documentation
Packages » Python » PythonObject » PythonObject and PythonObject
next | previous | forward | backward | up | index | toc

PythonObject and PythonObject -- logical conjunction of Python objects

Description

Perform the logical conjunction ("and") operation on Python objects.

i1 : toPython true and toPython true

o1 = True

o1 : PythonObject of class bool

If one of the arguments is a Macaulay2 object, then it is first converted to a Python object.

i2 : toPython true and false

o2 = false
i3 : false and toPython true

o3 = false

Unlike Macaulay2, Python supports using and with non-boolean objects. In this case, the first argument is returned if it is "falsy". Otherwise, the second argument is returned.

i4 : toPython 0 and toPython "foo"

o4 = 0

o4 : PythonObject of class int
i5 : toPython 5 and toPython "bar"

o5 = bar

o5 : PythonObject of class str

In Python, when the first argument is falsy, then is is returned immediately without evaluating the second argument. This is known as "short-circuiting". However, in Macaulay2, both arguments are evaluated before the Python conjunction method is called.

i6 : stopIfError = false

o6 = false
i7 : toPython 0 and 1/0
stdio:7:16:(3): error: division by zero

However, if the first argument is the Macaulay2 false object, then short-cicuiting will occur.

i8 : false and pythonValue "1/0"

o8 = false

See also

Ways to use this method:


The source of this document is in Python/doc/logical.m2:56:0.