Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8263645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:10:51+00:00 2026-06-08T04:10:51+00:00

The python documentation frequently speaks of containers. E.g. : If check_circular is False (default:

  • 0

The python documentation frequently speaks of “containers”. E.g. :

If check_circular is False (default: True), then the circular
reference check for container types will be skipped and a circular
reference will result in an OverflowError (or worse).

But I can’t find any official definition of containers, neither a list of them.

Edit

For Python 2.7.3:

Checked builtin types which are containers:

(isinstance(object, collections.Container) returns True)

  1. Containers which have a __contains__ method defined:

    • All builtin sequence types: Lists, bytearrays, strings, unicode strings and
      tuples.
    • Dictionaries
    • All builtin set types: sets and frozensets
  2. Containers which do not have a __contains__ method defined:

    • xrange objects

Checked builtin types which are not containers:

(isinstance(object, collections.Container) returns False):

  • Int objects
  • Float objects
  • Long objects
  • Boolean objects
  • Module objects
  • File objects
  • Buffer objects
  • The None object

Tell me which other builtin types you have checked for isinstance(object, collections.Container) and I’ll add them to the list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:10:53+00:00Added an answer on June 8, 2026 at 4:10 am

    Containers are any object that holds an arbitrary number of other objects. Generally, containers provide a way to access the contained objects and to iterate over them.

    Examples of containers include tuple, list, set, dict; these are the built-in containers. More container types are available in the collections module.

    Strictly speaking, the collections.abc.Container abstract base class (collections.Container in Python2) holds for any type that supports the in operator via the __contains__ magic method; so if you can write x in y then y is usually a container, but not always: an important point of difference between containers and general iterables is that when iterated over, containers will return existing objects that they hold a reference to, while generators and e.g. file objects will create a new object each time. This has implications for garbage collection and deep object traversal (e.g. deepcopy and serialisation).

    As an example, iter(lambda: random.choice(range(6)), 0) supports the in operator, but it is certainly not a container!

    The intent of the Collections.abc.Container abstract base class in only considering the __contains__ magic method and not other ways of supporting the in operator is that a true container should be able to test for containment in a single operation and without observably changing internal state. Since Collections.abc.Container defines __contains__ as an abstract method, you are guaranteed that if isinstance(x, collections.abc.Container) then x supports the in operator.

    In practice, then, all containers will have the __contains__ magic method. However, when testing whether an object is a container you should use isinstance(x, collections.abc.Container) for clarity and for forward compatibility should the Container subclass check ever be changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to my interpretation of Python 2.7.2 documentation for Built-In Types 5.7 Set Types
Python documentation to Popen states: Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read
I am trying to do python documentation generation with Sphinx. The problem is that
All the examples I've seen of sock.listen(5) in the python documentation suggest I should
I do not fully understand classes. I have read the python documentation and several
The Python 2 documentation says: Built-in Functions: map(function, iterable, ...) Apply function to every
How to document methods with parameters using Python's documentation strings? PEP 257 gives this
So I'm sure this is a stupid question, but I've looked through Python's documentation
I have looked in the official documentation for python, but i cannot seem to
I was just pleasantly surprised to came across the documentation of Python's compiler package

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.