Alison covers this very nicely. Two options that I find very useful are saying something when they first interrupt you:
I've only got 5 minutes to talk, and then I need to get back to work.
I'm a bit busy right now. But if you come back in 45 minutes, I should have a few minutes free.
In other words, deflect them right off, in a friendly and ...
I suggest pushing towards making his teaching effective.
The first step is to point out that very few people learn well just watching someone program, and in particular it does not work for you. You need to have your fingers on the keyboard, listen to what he tells you to do, ask questions until you understand it, and then type.
He may find actually ...
There's also the thing about him being my team leader, I feel like I
can't use the "I am really busy" line because it would imply that he
doesn't have anything to do...
I want to keep a cordial professional relationship. How can I
communicate all this without being rude?
Avoiding the "I am really busy" line is not implying anything, nor is it ...