Deities are mysterious figures that work in mysterious ways. You gain piety for doing things that they appreciate. Different deities appreciate different things.
Praying to a god grants passive piety acquisition. It also allows you to wish for favors from that god. However, be warned: praying to another god may have fairly negative consequences! It may be useful to create altars, that can amplify effects of prayer, in certain cases. But it might backfire in other cases.