The best advice on the matter I know of comes from the prologue of Zed Shaw's Learn Python The Hard Way:
This simple book is meant to get you
started in programming. The title says
it’s the hard way to learn to write
code; but it’s actually not. It’s only
the “hard” way because it’s the way
people used to teach things. With the
help of this book, you will do the
incredibly simple things that all
programmers need to do to learn a
- Go through each exercise.
- Type in each sample exactly.
- Make it run.
That’s it. This will be very difﬁcult
at ﬁrst, but stick with it.
And later on he elaborates:
It seems stupidly obvious, but, if you
have a problem typing, you will have a
problem learning to code. Especially
if you have a problem typing the
fairly odd characters in source code.
Without this simple skill you will be
unable to learn even the most basic
things about how software works.
Typing the code samples and getting
them to run will help you learn the
names of the symbols, get familiar
with typing them, and get you reading
Almost all of the prologue is dedicated to why typing code is preferred, there is no point to copy it here, there's a free pdf version of the book you can read.
So, to answer your question, I always type in the code. Every time you choose to type the code instead of just compiling / running the accompanying code you actually get some valuable practice and extra muscle memory points in the language's syntax, conventions and quirks. It's not just the code that matters, unless all you want to achieve is reading the language.
Python, where indentation is a language requirement and not a matter of style, is a perfect example of why you need to type everything when learning.