🔥 BLACK FRIDAY SALE1 course ₹199·any 3 courses ₹399 for 3 months·ALL courses + 1 mock interview ₹599 for 6 monthsClaim offer →

Python · The Python Data Model · Intermediate · 28 min read

Python Special Methods for Containers: Sequences, Mappings, Slicing and the collections.abc Mixins

Build custom containers that behave like built-ins. Learn the sequence and mapping protocols, __getitem__ with integers and slices, __len__, __contains__, __iter__, mutation methods, __missing__, using collections.abc base classes to get mixin methods for free, UserDict versus subclassing dict, and design guidance for ring buffers, case-insensitive mappings and matrices.

Python Special Methods for Containers: Sequences, Mappings, Slicing and the collections.abc Mixins: lesson illustration

A first look

  • Intermediate level · 28 min read
  • 7 interview questions with model answers
  • The Python Data Model · Python Mastery

You will learn to

  • The container protocols and which special methods each requires
  • Building a read-only sequence and supporting slices properly
  • Building a mutable sequence and a mapping with collections.abc
  • …and 3 more topics inside
Create an account to start

Create a free account to see what this lesson covers

  • Every free lesson in every section, in full
  • Track your progress and pick up where you left off
  • Free practice questions and an incident simulation
  • Takes under a minute: name, email and a password

No card needed. Full access to Python is a paid upgrade you can choose later.