diff --git a/README.md b/README.md index 9d243d8..a761c2c 100644 --- a/README.md +++ b/README.md @@ -1033,6 +1033,15 @@ class : * **Function field() is needed because `': list = []'` would make a list that is shared among all instances.** * **Default_factory can be any callable.** +### Slots +**Mechanism that restricts objects to attributes listed in 'slots' and significantly reduces their memory footprint.** + +``` +class MyClassWithSlots: + __slots__ = ['a'] + def __init__(self): + self.a = 1 +``` ### Copy ```python diff --git a/index.html b/index.html index e4d3268..8ece0e5 100644 --- a/index.html +++ b/index.html @@ -974,6 +974,13 @@ Z = dataclasses.make_dataclass('Z', [Function field() is needed because '<attr_name>: list = []' would make a list that is shared among all instances.
  • Default_factory can be any callable.
  • +

    Slots

    +

    Mechanism that restricts objects to attributes listed in 'slots' and significantly reduces their memory footprint.

    +
    class MyClassWithSlots:
    +    __slots__ = ['a']
    +    def __init__(self):
    +        self.a = 1
    +

    Copy

    from copy import copy, deepcopy
     <object> = copy(<object>)
    diff --git a/web/image_social.png b/web/image_social.png
    new file mode 100644
    index 0000000..4dd9f64
    Binary files /dev/null and b/web/image_social.png differ