Real Python Podcast Episode #196 Title Artwork

Episode 196: Exploring Duck Typing in Python & Dynamics of Monkey Patching

The Real Python Podcast

Mar 15, 2024 50m

What are the advantages of determining the type of an object by how it behaves? What coding circumstances are not a good fit for duck typing? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder’s Weekly articles and projects.

Episode Sponsor:

Christopher covers a recent Real Python tutorial by Leodanis Pozo Ramos titled Duck Typing in Python: Writing Flexible and Decoupled Code. The tutorial explains the concepts of duck typing within object-oriented programming and its use within Python’s built-in tools.

We discuss a recent article on monkey patching in Python. This practice of dynamically modifying a class or module’s behavior at runtime allows for testing, debugging, and experimentation.

We also share several other articles and projects from the Python community, including a news roundup, why names are not the same as objects in Python, using IPython Jupyter magic commands, a discussion about becoming a senior developer, a data exploration challenge, a Python evaluation game, and a terminal UI for regex testing.

This week’s episode is brought to you by Sentry.


  • 00:00:00 – Introduction
  • 00:02:38 – Listener feedback
  • 00:04:02 – DjangoCon US Call for Proposals
  • 00:04:38 – White House Recommends Use of Python
  • 00:05:41 – JupyterLab 4.1 and Notebook 7.1 Released
  • 00:06:05 – What’s in a Name?
  • 00:11:52 – Duck Typing in Python: Writing Flexible and Decoupled Code
  • 00:15:07 – Sponsor: Sentry
  • 00:16:11 – Using IPython Jupyter Magic Commands
  • 00:22:31 – A Guide to Monkey Patching
  • 00:25:27 – Falsehoods Junior Developers Believe About Becoming Senior
  • 00:33:01 – Video Course Spotlight
  • 00:34:11 – Falsehoods continued
  • 00:43:43 – Where in the data?
  • 00:46:55 – the eval game
  • 00:48:03 – rexi: Terminal UI for Regex Testing
  • 00:49:43 – Thanks and goodbye


Show Links:

  • What’s in a Name? – An article about names in Python, and why they’re not the same as objects. The article discusses reference counts and namespaces.
  • Duck Typing in Python: Writing Flexible and Decoupled Code – In this tutorial, you’ll learn about duck typing in Python. It’s a typing system based on objects’ behaviors rather than on inheritance. By taking advantage of duck typing, you can create flexible and decoupled sets of Python classes that you can use together or individually.
  • Using IPython Jupyter Magic Commands – “IPython Jupyter Magic commands (e.g. lines in notebook cells starting with % or %%) can decorate a notebook cell, or line, to modify its behavior.” This article shows you how to define them and where they can be useful.
  • Monkeying Around With Python: A Guide to Monkey Patching – Monkey patching is the practice of modifying live code. This article shows you how it’s done and why and when to use the practice.



Additional Links:

Level Up Your Python Skills With These Courses: