Solar flare emission is detected in all EM bands and variations in flux density of solar energetic particles. Often the EM radiation generated in solar and stellar flares shows a pronounced oscillatory pattern, with characteristic periods ranging from a fraction of a second to several minutes. These oscillations are referred to as quasi-periodic pulsations (QPPs), to emphasise that they often contain apparent amplitude and period modulation. We review the current understanding of quasi-periodic pulsations in solar and stellar flares. In particular, we focus on the possible physical mechanisms, with an emphasis on the underlying physics that generates the resultant range of periodicities. These physical mechanisms include MHD oscillations, self-oscillatory mechanisms, oscillatory reconnection/reconnection reversal, wave-driven reconnection, two loop coalescence, MHD flow over-stability, the equivalent LCR-contour mechanism, and thermal-dynamical cycles. We also provide a histogram of all QPP events published in the literature at this time. The occurrence of QPPs puts additional constraints on the interpretation and understanding of the fundamental processes operating in flares, e.g. magnetic energy liberation and particle acceleration. Therefore, a full understanding of QPPs is essential in order to work towards an integrated model of solar and stellar flares.