Where to Go Next

You can install Python and run a script. You know the core value types, variables, f-strings, and how to take and convert input. You can branch with if/elif/else, repeat work with for and while, hold a group of values in a list or a dictionary, write your own functions, import from the standard library, read and write a text file, and catch a specific error instead of letting your script crash. Chapter 11 put every piece of that into one real, working script. That's not a small list for a first book.

This book left a lot out on purpose. A short list of what's next, and where it lives.

The shape that outlasts this book

track.py's load, act, save shape isn't specific to an expense tracker. Almost every small program you write from here on will be some version of it: read in what already exists, do something with it, write the result back out or show it to someone. A to-do list, a habit tracker, a script that tidies up a folder of downloads, all fit the same three beats. When you're staring at a blank file trying to figure out where to start on your own idea, "what am I loading, what am I doing to it, what am I saving" is a genuinely useful first question to ask.

Classes and object-oriented Python

Every value you've used, a str, a list, a dict, is built from a class under the hood, and .append() and .strip() are methods defined on those classes. Writing your own is the natural next step once functions and dictionaries feel comfortable, and it's the whole subject of Object-Oriented Python, already part of this series: __init__, self, the dunder methods that make your own objects print and compare well, inheritance, properties, and dataclasses.

Files, properly

Chapter 9 kept things simple on purpose: a plain split(","), no encodings, no pathlib. Python File Handling, also already part of this series, covers the real depth: the csv module for data that has commas in it, the json module, pathlib for building and inspecting paths, text encodings and why they matter, and safely replacing a file without risking the version already on disk.

Other directions, briefly

  • Decorators and closures. You'll see @something above a function in other people's code long before you need to write your own. It's built on the idea that a function is a value like any other, which you already know from passing functions to sorted()-style tools once you meet them.
  • Virtual environments and third-party packages. Every example in this book used only what Python ships with. The moment you want a package someone else wrote, pip install requests and the like, you'll want a virtual environment first, so packages for one project don't collide with another. python -m venv .venv is the one command to know to start.
  • Type hints. Writing def total(expenses: list) -> float: documents what a function expects, and tools like mypy can check it for you before you ever run the code. Worth picking up once you're writing functions other people (or future you) will call.
  • Testing. This book's own examples are checked every time the book is built, the same spirit as a testing framework like pytest: write down what a function should do, then let the computer check it stays that way.

A project to try

Extend track.py yourself, using nothing but what this book covered.

Add a function expenses_in(expenses, category) that returns every entry matching one category, the same shape as Chapter 11's expenses_over(). Then change main() so it loops, using a while loop, asking "Add another? (y/n)" after each entry, instead of only ever recording one before saving. Keep every piece that touches input() inside main(), exactly like Chapter 11 did, and keep expenses_in() itself free of input() so you can test it the same way this book tested everything else: call it with a list you build by hand and check what comes back.

Further reading

  • The Python Tutorial on docs.python.org covers everything in this book and more, written for someone who already codes in another language; a useful second pass once you've finished this one.
  • Automate the Boring Stuff with Python, free to read online, goes on from roughly where this book stops into file and web automation, if that's the direction you want next.

The rest of this track

The full Foundations track of The Python Crown, in the order to read it:

  • Python from Zero (this book)
  • Python Data Structures in Depth
  • Object-Oriented Python
  • The Python Standard Library

Whichever titles are ready are at king-coding.com.