Skip to Content
Fluent Python 第2版 ―Pythonicな思考とコーディング手法
book

Fluent Python 第2版 ―Pythonicな思考とコーディング手法

by Luciano Ramalho, 牧野 聡
November 2025
Intermediate to advanced
984 pages
16h 17m
Japanese
O'Reilly Japan, Inc.
Content preview from Fluent Python 第2版 ―Pythonicな思考とコーディング手法

14章継承の光と影

私たちは継承そのものについてのより良い理論を必要としていました(そして今も必要としています)。例えば継承やインスタンス化(これもある意味では継承です)では、実用的な側面(コードを再設計して総量を減らす、など)と意味的な側面(特殊化、汎化、種分化などさまざま)とが混同して扱われています。

—— Alan Kay

『The Early History of Smalltalk』†1

[†1] Alan Kay、『The Early History of Smalltalk』、SIGPLAN Not. 28, 3(1993年3月)、69--95ページ。https://fpy.li/14-1で公開。友人Christiano Andersonが紹介してくれました。

この章では継承と子クラスについて解説します。これらの概念に関しては基礎知識を前提として議論を進めてゆきますが、『The Python Tutorial』(https://fpy.li/14-2)などが参考になるでしょう。また、Java、C#、C++といった他のオブジェクト指向言語での経験も役立ちます。本書では、Pythonに固有の以下の4点に注目します。

  • super()関数
  • 組み込み型の子クラスを定義する際の注意点
  • 多重継承とMRO(メソッド解決順序)
  • ミックスインのクラス

多重継承とは、1つのクラスが複数の基底クラスを持つことです。C++ではサポートされていますが、JavaやC#ではサポートされていません。多くの人々は、多重継承はメリットよりもデメリットのほうが多いと考えています。初期のC++コードでの乱用を受けて、Javaでは意図的に多重継承の機能が除外されました。

この章ではまず、未経験者向けに多重継承を紹介します。単一継承と多重継承のいずれを使う場合についても、適切な実装のための指針を明らかにします。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Fluent Python ―Pythonicな思考とコーディング手法

Fluent Python ―Pythonicな思考とコーディング手法

Luciano Ramalho, 豊沢 聡, 桑井 博之, 梶原 玲子

Publisher Resources

ISBN: 9784814401284Publisher Website