Well actually, when water ( H2O ) undergoes electrolysis they get split into OH- ions and H+. Now at cathode ( Cathode is the negatively charged platinum electrode ) : H+ will gain one electron and will become H. Now this H again combines with another H and finally becomes H2 molecule. At anode ( Anode is the positively charged platinum electrode ) : The OH- ion will lose one electron. Thus 4OH will give 2 molecules of H2O and one molecule of O2. For better understanding look at the following equation below.
At cathode :
H+ + e- --> H
H + H --> H2
At cathode :
OH- --> OH + e-
4OH --> 2H2O + O2
Complete equation :
2H2O --(electrolysis)--> 2H2 + O2
I hope this helped you.