Skip to main content

[ ![O'Reilly home](https://cdn.oreillystatic.com/images/sitewide-
headers/oreilly_logo_mark_red.svg) ](https://www.oreilly.com "home page")

  *     * [ Sign In ](/member/login/?next=/library/view/fluent-python/9781491946237/ch01.html)
    * [ Try Now ](https://learning.oreilly.com/start-trial/)
  *     * [ Teams ](https://www.oreilly.com/online-learning/teams.html)
      * [ For business ](https://www.oreilly.com/online-learning/business.html)
      * [ For government ](https://www.oreilly.com/online-learning/government.html)
      * [ For higher ed ](https://www.oreilly.com/online-learning/academic.html)
    * [ Individuals ](https://www.oreilly.com/online-learning/individuals.html)
    * [ Features ](https://www.oreilly.com/online-learning/features.html)
      * [ All features ](https://www.oreilly.com/online-learning/features.html)
      * [ Courses ](https://www.oreilly.com/online-learning/courses.html)
      * [ Certifications ](https://www.oreilly.com/online-learning/feature-certification.html)
      * [ Interactive learning ](https://www.oreilly.com/online-learning/intro-interactive-learning.html)
      * [ Live events ](https://www.oreilly.com/online-learning/live-events.html)
      * [ Answers ](https://www.oreilly.com/online-learning/feature-answers.html)
      * [ Insights reporting ](https://www.oreilly.com/online-learning/insights-dashboard.html)
    * [ Blog ](https://www.oreilly.com/radar/)
    * [ Content sponsorship ](https://www.oreilly.com/content-marketing-solutions.html)

# [ Fluent Python by Luciano Ramalho
](https://learning.oreilly.com/library/view/fluent-python/9781491946237/)

[ Buy on Amazon
](https://www.amazon.com/_/dp/1491946008?smid=ATVPDKIKX0DER&_encoding=UTF8&tag=oreilly20-20)

Get full access to _Fluent Python_ and 60K+ other titles, with a free 10-day
trial of O'Reilly.

There are also live events, courses curated by job role,  and more.

[ Start your free trial ](https://learning.oreilly.com/start-trial/)

#  Chapter 1.  The Python Data Model

> Guido’s sense of the aesthetics of language design is amazing. I’ve met many
> fine language designers who could build theoretically beautiful languages
> that no one would ever use, but Guido is one of those rare people who can
> build a language that is just slightly less theoretically beautiful but
> thereby is a joy to write programs in.  [ 1 ](ch01.html#idm139636571282336)
>
> Jim Hugunin,  Creator of Jython, cocreator of AspectJ, architect of the .Net
> DLR

One of the best qualities of Python is its consistency. After working with
Python for a while, you are able to start making informed, correct guesses
about features that are new to you.

However, if you learned another object-oriented language before Python, you
may have found it strange to use ` len(collection) ` instead of `
collection.len() ` . This apparent oddity is the tip of an iceberg that, when
properly understood, is the key to everything we call _Pythonic_ . The iceberg
is called the Python data model, and it describes the API that you can use to
make your own objects play well with the most idiomatic language features.

You can think of the data model as a description of Python as a framework. It
formalizes the interfaces of the building blocks of the language itself, such
as sequences, iterators, functions, classes, context managers, and so on.

While coding with any framework, you spend a lot of time implementing methods
that are called by the framework. The same happens when you leverage the
Python data model. The Python interpreter invokes special methods to perform
basic object operations, often triggered by special syntax. The special method
names are always written with leading and trailing double underscores (i.e., `
__getitem__ ` ). For example, the syntax ` obj[key] ` is supported by the `
__getitem__ ` special method. In order to evaluate ` my_collection[key] ` ,
the interpreter calls ` my_collection.__getitem__(key) ` .

The special method name