All Canon EF, EF-L and EF-S series lenses are compatible with the 40D, and every Canon Digital SLR since the 300D. Exceptions are the older 10D, D30 & D60's which can't use the EF-S series... if I recall correctly. If not, someone please correct me.
As far as the lens goes, Canon makes different quality of lenses. The EF-S lenses are made to fit small sensor bodies with a 1.6 crop factor, otherwise comparable EF quality.
The EF lenses are entry level, so lack weather seal and higher quality corrective glass and general build which helps keep their price down.
The "L" series are considered Canon Pro, or Luxury lenses, which offer the best optics and sealing available from them.
All 3 series have some lenses with the addition of "Image Stabilization" which adds to their price.
Basically, the more you invest, the better the lens.