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

PythonObject or PythonObject -- logical disjunction of Python objects

Description

Perform the logical disjunction ("or") operation on Python objects.

i1 : toPython true or 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 or false

o2 = True

o2 : PythonObject of class bool
i3 : false or toPython true

o3 = True

o3 : PythonObject of class bool

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

i4 : toPython 0 or toPython "foo"

o4 = foo

o4 : PythonObject of class str
i5 : toPython 5 or toPython "bar"

o5 = 5

o5 : PythonObject of class int

In Python, when the first argument is truthy, 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 disjunction method is called.

i6 : stopIfError = false

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

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

i8 : true or pythonValue "1/0"

o8 = true

See also

Ways to use this method:


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