Search code examples
pythonmembership

What does membership mean?


What is membership, searching for this it looks like that term is used not just in Python.

I found it while learning about sets, the documentation says:

Common uses include membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference.


Solution

  • Membership means that a value is in the set:

    member in someset
    

    is True if member is indeed one of the values present in the set. Those values in the set are called 'members'.

    The term is a mathematical one and basically is synonimous with 'element', which is what most people use when talking about membership in lists and tuples.

    The in operator tests for membership, whatever the container you are testing against:

    The operators in and not in test for collection membership

    Sets are not the only collections; any container with elements can support membership. In addition to sets, lists and tuples, strings and dictionaries also support membership tests for example.