It is better to know that the compiler doesn't optimize unless you set it, than later optimize your code when you find it runs slowly but you never learnt how to enable optimization.
So here is my advice: One day soonish, learn the optimization options for your compiler, or at least the default level of optimization. Generally, you should look it up when/before you start having speed problems and decide to optimize the code. At this point, optimizing the algorithms is probably the correct answer, but don't bother replacing your n=n+1 when you might want to change the 1, or the n later, when the compiler can treat it as n++ transparently if you just enable optimization(Again, don't bother until you need it, and check the compiler optimization before trying to optimize the code itself. And finding a faster method of achieving the same result is usually the best choice, not finding faster code or having the compiler generate faster code.)
I'm sorry, but this is simply bad advice. I can't really sugar-coat it: it is bogus information that is not relevant to the topic at hand.
Standard Python doesn't have an optimizing compiler*!I know you mean well, but seriously, please. You're not helping. I would politely suggest that you should learn how Python works if you want to contribute, as that's the language he's currently using. And I'm taking my own advice here: I'm re-reading ThinkPython myself right now, in order to be better able to answer questions.
* - Other methods are used for code optimization that have little, if anything, to do with the tools running Python. The idea of an optimizing compiler in Python is so silly that it's been used as an April Fool's joke. I mean, for fuck's sake, man, Standard Python is an
interpreted language to begin with, why are you even talking about compilers at the start? It's like bringing up a snowmobile in a car conversation, it's just got nothing to do with it.
(EDIT: Also, for people who
are learning C++ and might be reading this thread: it's harmless-but-very-unnecessary advice there, to dive into optimization early on until you understand C++
absolutely god damned cold. The marginal performance benefit of hardcore compiler wank are almost undetectable below a staggering number of iterations--modern computers are simply Fast Enough and default compiler settings are smart enough that fiddling with them will not get you far. And if you're working on stuff at that scale where it starts to really matter, you should already know enough to go research the topic without qwertyuiopas telling you to do it. If you don't, you don't need it yet and are probably aiming too high.)