Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Python 4 Kids: Python for Kids Book: Project 9

$
0
0

In these posts I outline the contents of each project in my book Python For Kids For Dummies.  If you have questions or comments about the project listed in the title post them here. Any improvements will also be listed here.

What’s in Project 9 (Address Book)

While Project 6 introduced the concept of objects and showed how even a lowly string is actually an object, Project 9 is about how you can make your own objects using the class keyword.  Project 9 uses classes to implement a simple address book application.  I discuss the difference between a class and an instance of the class and the importance of having a reference variable (self) so that an instance can refer to itself. You learn about constructor functions and how to override a method (__repr__) to make print statements work properly on your custom method.

Since having an address book is not much use if you can’t save and update it, I also introduce the pickle module. It is used to store general Python objects (if they’re hashable!).  The address book is given save and load functions as well as a rudimentary user interface.



Viewing all articles
Browse latest Browse all 22462

Trending Articles