The reason for the presence of both H+ and OH- ions in pure water lies in the polarity of the water molecule. Due to the difference in electronegativity between oxygen and hydrogen, the oxygen atom slightly attracts electrons towards itself, creating a slight negative charge on the oxygen end and a slight positive charge on the hydrogen end of the molecule. This allows other water molecules to interact with these partially charged regions, leading to the occasional transfer of hydrogen ions (protons) from one water molecule to another.
While the concentration of these ions in pure water is very low (approximately 1 x 10^-7 moles per liter), it is this balance between H+ and OH- ions that determines the pH of water and its acidic or basic nature. Deviations from this balance, where the concentration of H+ ions increases or decreases, result in acidic or basic solutions, respectively.