Macaulay2 » Documentation
Packages » Python » PythonObject » isMember(PythonObject,PythonObject)
next | previous | forward | backward | up | index | toc

isMember(PythonObject,PythonObject) -- test membership in a python object

Description

This tests whether x is a member of y. This is equivalent to x in y in Python.

i1 : isMember(toPython 3, toPython {1, 2, 3})

o1 = true
i2 : isMember(toPython 4, toPython {1, 2, 3})

o2 = false

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

i3 : isMember(toPython 3, {1, 2, 3})

o3 = true
i4 : isMember(4, toPython {1, 2, 3})

o4 = false

When used with dictionaries, which are Python's equivalent of Macaulay2 hash tables, the keys are tested for membership. In this sense, it is like the Macaulay2 #? and .? operators.

i5 : isMember("foo", toPython hashTable {"foo" => "bar"})

o5 = true
i6 : isMember("bar", toPython hashTable {"foo" => "bar"})

o6 = false

Ways to use this method:


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