Synchrotron radiation and Compton scattering are widely accepted as the most likely emission mechanisms of some astrophysical phenomena, such as gamma-ray bursts (GRBs) and active galactic nuclei. The measurement of the polarization of photons provides a useful tool to distinguish different emission mechanisms and structures of the emission region. Based on the differential cross section of a polarized photon scattered by an unpolarized electron of any initial momentum, we derive an analytical formula of polarization for beamed photons scattered by isotropic electrons with a power-law distribution. Numerical calculations are carried out in four special cases: electrons at rest, Thomson limit, head-on collision, and monochromatic electrons. It is found that the maximum polarization can be as high as 100% for low energy photons, if the electrons are at rest. Although polarization is highly suppressed due to the isotropic electrons, a maximum value of similar to 10%-20% can still be achieved. The Compton scattering process can be used to explain the polarization of GRB 041219A and GRB 100826A.