Work function is a fundamental property of a material's surface. It is playing an ever more important role in engineering new energy materials and efficient energy devices, especially in the field of photovoltaic devices, catalysis, semiconductor heterojunctions, nanotechnology, and electrochemistry. Using ambient pressure X-ray photoelectron spectroscopy (APXPS), we have measured the binding energies of core level photoelectrons of Ar gas in the vicinity of several reference materials with known work functions (Au(111), Pt(111), graphite) and PbS nanoparticles. We demonstrate an unambiguously negative correlation between the work functions of reference samples and the binding energies of Ar 2p core level photoelectrons detected from the Ar gas near the sample surface region. Using this experimentally determined linear relationship between the surface work function and Ar gas core level photoelectron binding energy, we can measure the surface work function of different materials under different gas environments. To demonstrate the potential applications of this ambient pressure XPS technique in nanotechnology and solar energy research, we investigate the work functions of PbS nanoparticles with various capping ligands: methoxide, mercaptopropionic acid, and ethanedithiol. Significant Fermi level position changes are observed for PbS nanoparticles when the nanoparticle size and capping ligands are varied. The corresponding changes in the valence band maximum illustrate that an efficient quantum dot solar cell design has to take into account the electrochemical effect of the capping ligand as well.