Get a feel for the teacher first, before going off the taught subject, and ask privately towards the end of class, not in front of everyone.
I've had teachers who were very strict on you only doing what they teach, and I've had teachers who were delighted that I wanted to go off the beaten path, so to speak.