Principle of electromagnetic induction
There is a magnet and a coil in the flashlight. When the hand is grasped, the coil can rotate, allowing it to cut the magnetic field lines and generate an induced current.
The alternating current we now use also uses the principle of electromagnetic induction.
The principle of electromagnetic induction was discovered by Faraday.