The full response here requires a deep dive into the immune system and self tolerance but basically, yeah, the immune system learns how to know what is ‘self’ and what is ‘else’. And this is specific to a person’s actual body (ie the reason someone develops organ rejection in the event of a transplant or can develop graft vs host disease in the event of a stem cell transplant (new immune system attacks body bc it isn’t ‘self’).
It’s really an amazing system