Definition of Slots

Generally, slots are narrow opening, like a groove or a slit: for example a slot to input coins in a vending machine or a mail slot.

A slot can also be an assigned place in a schedule or a sequence: the time slot for a meeting or a TV program.

Slots are known as slot machines as well.

In computers the term "slot" is used for for expansion slots. An expansion slot is an opening located inside a computer on the motherboard or riser board that allows additional boards to be connected.
This website is supported by:Linux and Python Courses and Seminars

Python 3

Classroom Training Courses

The goal of this website is to provide educational material,
allowing you to learn Python on your own.
Nevertheless, it is faster and more efficient to attend a "real"
Python course in a classroom, with
an experienced trainer. So why not attend one of the live
Python courses in Strasbourg, Paris, Luxembourg, Amsterdam, Zürich / Zurich, Vienna / Wien, London, Berlin, Munich, Hamburg, Frankfurt, Stuttgart, or Lake Constance by Bernd Klein, the author of this tutorial?

You can book on-site classes at your company or organization, e.g. in England, Switzerland, Austria, Germany,
France, Belgium, the Netherlands, Luxembourg, Poland, UK, Italy and other locations in Europe and in Canada.

Slots

Avoiding Dynamically Created Attributes

The attributes of objects are stored in a dictionary "__dict__". Like any other dictionary,
a dictionary used for attribute storage doesn't have a fixed number of elements. In other words,
you can add elements
to dictionaries after they have been defined, as we have seen in our chapter on dictionaries. This
is the reason, why you can dynamically add attributes to objects of classes that we have created so far:

Using a dictionary for attribute storage is very convenient, but it can mean a waste of
space for objects, which have only a small amount of instance variables. The space
consumption can become critical when creating large numbers of instances. Slots are a
nice way to work around this space consumption problem. Instead of having a dynamic dict that
allows adding attributes to objects dynamically, slots provide a static structure which prohibits
additions after the creation of an instance.

When we design a class, we can use slots to prevent the dynamic creation of attributes.
To define slots, you have to define a list with the name __slots__. The list has to contain
all the attributes, you want to use. We demonstrate this in the following class, in which the slots
list contains only the name for an attribute "val".

We mentioned in the beginning that slots are preventing a waste of space with objects.
Since Python 3.3 this advantage is not as impressive any more. With Python 3.3
Key-Sharing Dictionaries are used for the storage of objects. The attributes of the instances are capable of sharing part of their internal storage between each other, i.e. the part which stores the keys and their corresponding hashes.
This helps to reduce the memory consumption of programs, which create many instances
of non-builtin types.