If you live in an old house and keep receiving shocks when you turn on the lights, check the outlets. If they have only two holes, you probably have outdated circuitry that isn't grounded. If you live in a house with updated, grounded circuitry and you still get shocks, however, the problem may be a buildup of static electricity from the carpeting. In both cases, the electricity uses you as a path to ground.
Before the electric code began to require grounding in all newly installed residential circuitry, houses were wired with two-strand electrical cable with a hot and neutral wire. In this kind of wiring, even a small failure of the wire insulation can expose a person to electric shock. It happens because the person's body completes a circuit between the exposed wiring and the earth. Wearing rubber-soled shoes in the house can reduce the risk of this kind of shock, but a safer solution is to upgrade the wiring.
Even if your house has code-approved grounded wiring, you still can get a shock by touching exposed wires or metal that is in contact with them. This rarely happens intentionally. It is more likely to be the result of handling a poorly insulated appliance, or one with a loose internal connection, under conditions that give electricity a path to ground through your body. To prevent this, avoid using old appliances, especially those with loose connections, and install ground fault interrupting (GFI) outlets in the bathroom, kitchen, outdoors and any location where wet conditions increase the risk of unintentional grounding.
If your house has carpeting, it is almost impossible to avoid static shocks, particularly on dry days. The movement of your feet on the carpet creates a buildup of static electricity as electrons from the carpet move from the carpet into your body and electrically energize it. When you touch any metal surface, like a doorknob, you create a circuit that allows the electrons to flow, and you get a shock. While uncomfortable, shocks from static electricity are normal. You can reduce their severity by frequently touching metal objects to ground yourself before the buildup of electricity in your body becomes too large.
If you experience frequent shocks from a particular switch or outlet, repair it as soon as possible. You may be getting the shock from a loose connection or short circuit which, if left unattended, could eventually electrocute someone or cause a fire. If you get shocks from a particular appliance, have it serviced or discard it. Use of such an appliance under the wrong conditions could be lethal. Frequent shocks in a house with outdated wiring should alert you to the need to upgrade and ground your circuitry.