1 Improving your Python with practice
Python’s continued rise stems from its combination of approachability and power. It offers “low floors and high ceilings”: newcomers can become productive quickly thanks to simple, consistent syntax, while experienced developers leverage rich built-ins, first-class functions, generators, and cross-platform support to solve serious problems with little code. Because it is open source and guided by its community, Python serves an unusually broad range of domains—from data and web work to devops, testing, research, and more—and the same language that introduces students to programming also runs mission-critical systems.
Yet writing effective Python is about idioms as much as syntax. Many practitioners pick it up on the job and produce working but unidiomatic, verbose, or less maintainable code, often importing habits from other languages. Mastery comes from deliberate practice that internalizes Python’s mental model—ideas like sequences, positional arguments, and attributes—and reveals the capabilities of its data structures and functions. This book positions itself as a second step: a practice-driven path to think and code “the Pythonic way,” embracing experimentation, reflection on mistakes, and a preference for readable, maintainable solutions over premature focus on speed.
It targets readers with foundational experience (roughly up to a year), aiming to sharpen fluency and judgment—choosing the right data structure or abstraction so solutions become simpler and faster. Exercises progress from core types (numbers, strings, lists/tuples, dictionaries/sets, files) to code organization and iteration (functions, functional techniques such as comprehensions, modules and packages, object-oriented programming, iterators and generators). All you need is a modern Python (3.10+) and a place to run code; for each exercise, attempt a solution, study the provided explanation, and compare approaches to cement insights and build confidence.
What about AI?
When I was an undergraduate in the early 1990s, I took a course in artificial intelligence. Even then, AI seemed like the next big thing, but after several decades of AI researchers claiming success was around the corner, most people had given up hope of ever seeing it happen.
And then, just a few years ago, many decades of AI research finally paid off: ChatGPT and other chatbots demonstrated that they could interact with people in a human-like way. Moreover, they could answer our questions, both about the world and about documents that we uploaded via the chatbot’s interface.
And most amazingly, these chatbots could code. And of course, they could code in Python.
I’m not against AI. I personally benefit every day from these amazing technologies, and my monthly payments for ChatGPT, Claude, and GitHub’s Copilot are worth every penny.
But I say this as an experienced developer, one who has learned how to code, can recognize mistakes and bad code, and isn’t afraid to say "no" to a chatbot. I see AI as a brainstorming partner or intellectual adversary with whom I can flesh out my ideas, not as an expert who can and should write code for me.
When ChatGPT first came out, no small number of people quipped that "the next big programming language is English." After all, if you can describe what you want to do in English and get code out of the chatbot, why not? There’s even a term for this, "vibe-coding."
There are at least three problems with vibe-coding, though:
First and foremost, the code often doesn’t work, or has holes, or has security issues. There’s a reason why we use programming languages, which are artificial and unambiguous, rather than human languages, which are natural and full of ambiguity, to tell computers what to do. If you’ve ever worked on a software project, you know that even the most rigorous specifications will often contain some ambiguity, leading to missed deadlines or even catastrophic failures.
Anyone who has ever done contract programming work for a non-technical client knows that the distance between their specification, well meaning as it might be, and actual working code is huge. The notion that the entire world will soon be vibe-coding their own projects, rather than asking programmers to do it for them, is unrealistic, to say the least.
A second problem with this approach is that AI tools are a tremendous help when you are an experienced coder. I’ve heard, and even seen, that when you use an AI-enabled editor or notebook, you can progress much more quickly than just on your own.
But remember that modern AI is basically a souped-up autocomplete. Which means that you need to set up the start of the function or class definition in order for the completion to make sense. And you need to inspect what the chatbot gave you before blindly accepting it.
So yes, by all means you should use an AI-based editor — but only after you have gained some experience.
Finally, and most significantly for this book: Using AI gives you the illusion of learning and progress, but actually impedes both. The only way to learn is to solve problems, reflect on your mistakes, and then move forward. It’s frustrating and slow, but that’s the only way.
Asking AI to help you solve the problem isn’t like someone training for a marathon wearing better running shoes. Rather, it’s like giving them a motororcycle. They’ll have the illusion that they can run in record time — but when push comes to shove, and they need to do the job under real-world conditons, they’ll either find themselves unable to do it, or will basically be showcasing the chatbot’s work, rather than their own.
For all of these reasons, I encourage you to turn off any AI-related enhancements that your editor, notebook, or other programming environment might offer when solving the problems in Python Workout. Go through each exercise, trying to understand how you might solve it. Then go ahead, and try to solve the problem itself. You’ll make mistakes, but that’s an important part of the learning process.
When you’re done with the book, and you re-activate the AI help in your editor, its suggestions (good and bad) will make sense to you. You’ll have a better sense of what to accept, and what to reject. And you’ll be ready to solve bigger and tougher problems than before.
Python Workout, Second Edition ebook for free