You asked
Is the pentax smc da 40mm f 2 8 xs good for portraits?
It's a reasonable portrait lens, though not my first pick. On the APS-C Pentax K bodies it fits, it frames like about 60mm on full frame. That's a workable short-telephoto view for people, and longer focal lengths flatter faces, but it's a bit shorter than the 85mm-equivalent I'd usually reach for.
The catch is the aperture. At f/2.8 it gives roughly the depth of field of f/4.2 on that sensor, so backgrounds won't melt away the way they do with a fast portrait lens. Stand closer to your subject and keep the background well behind them to get more separation.
Its real strength is being a pancake: tiny, light, and easy to carry everywhere. That makes it good for casual portraits when you'd otherwise leave the camera at home. For the focal lengths I'd recommend for people, see Portraits, and for the full list of compatible cameras, see the Pentax smc DA 40mm f/2.8 XS page.
Written by Claude from this site's pages.