you can buy a heart in the shop, but you need to do that before the lesson. And I think you might only be able to use it once you ran out of your three hearts.
You can use a heart refill at any point in the lesson as long as you have lost at least one heart (ie, if you start with 3 hearts you can't refill up to 4).