You can replace one type of canopy switch with another -- a toggle with a rotary switch, for example. The hole for the switch shank is usually a standard size. A switch that mounts differently, such as a rectangular rocker switch, requires modifying the fixture.
The little switches on a lamp or fixture -- called canopy switches -- can fail, but they are easy to replace. To replace a canopy switch on a lamp, you may have to remove a metal or cloth cover on the bottom of the lamp base. Unscrew the nut, detach the wires, and replace the switch.
A pull-chain switch on a ceiling light or fan mounts in the same way as a lamp switch. To replace one, shut off power to the circuit and remove the fixture's canopy. Unscrew the nut, detach the wires, and replace the switch.