Swearing / Using inappropriate words

Before You Begin
Pause and breathe. Even if this shouldn't be happening... accept that it is and embrace it with composure and calmness.
Calmness is the only way forward because without calm, there is no possibility for receptiveness and connection. Your child won't give to you any more than they see from you.
Never forget that a strong connection is fundamental, as there will be no correction in them if there is no connection with you.
The Core Problem
The don't understand appropriate verbal boundaries and are often seeking attention through using that poor language.
What Will Make It Worse
Reacting with anger or punishment for the child's language choices will likely worsen the situation.
Similarly, ignoring or dismissing the behavior without addressing the underlying issues can also lead to the continuation of inappropriate language.
What The Child Needs
1. To develop alternative communication skills: Teach the child better and more articulate ways to communicate what they are trying to say. Moreover, show them how to use humor, metaphors or other creative communication skills to draw people in when they talk, and earn the positive attention the child enjoys.
2. Reinforcing role-modeling: If your child hears you swearing they will inevitably start talking like you. Be sure to think about what you saying in daily life so you are not sending a mixed message to your child about swearing.
3. Clear boundaries: Clearly communicate the boundaries and expectations around appropriate behavior and let them know the consequences of using those words.
How To Have The Conversation With Your Child
Find a comfortable place free of distractions where the child can focus on talking with you.
Begin the conversation in a calm matter-of-fact tone, sharing that at some point every kid starts experimenting with saying swear (or inappropriate) words, whether for attention or because of novelty. Acknowledge that you have heard them using these words and that because this is obviously not okay, you are going to help them find better ways to have fun with words.
You shouldn't put a huge spotlight on the problem. Rather it will be more effective to set the boundaries of appropriate things to say and then to shift their focus to pointer #1. Have fun with it, and they will move on from using poor language to trying to be more and more clever in what they say.
Bear in mind that keeping this behavior corrected has a lot to do with what they hear you and others around them saying so be mindful that you are not contributing to the bad behavior. If their friend is the primary foul mouth, tell your child that it is up to their parent to stop them, but for the reasons you already talked about, it is not good and doesn't make it okay for your child to talk like that too.