Exercise 44

From Dictionaries to Objects

You should review the following exercises before doing this one:

  • Exercise 24, Introductory Dictionaries, to refresh your understanding of Dictionaries

  • Exercise 25, Dictionaries and Functions, for how you can put functions in dictionaries and call them

  • Exercise 26, Dictionaries and Modules, for how modules are just dictionaries behind the scenes and how changing the underlying __dict__ changes the module

In this exercise you’ll learn about Object-Oriented Programming by creating your own little object system using the previous information.

Step 1: Passing a Dict to a Function

Imagine you want to record information about people and then have them say things. Maybe this is a little video game with little ...

Get Learn Python the Hard Way: A Deceptively Simple Introduction to the Terrifyingly Beautiful World of Computers and Data Science, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.