Absolutely defensive. If he thought you were food he would have bit and held on or more likely wrapped. I've had ball pythons that were totally mellow for years strike one day when I startled them. No big deal, he'll be fine. Babies can get defensive at times as they need to protect themselves. It's much rarer in older snakes at least in my experience.