Most little kids go through the "potty mouth" phase, often around three years old. They get a big kick out of it. Sometimes, too, a child two or a little under may hear one bad word and keep saying it. My son was under two when he heard a teenagers (you can guess the word), and he went through a phase of saying it (when he couldn't really say much else). With that one, I knew he was way too little to understand and that it would pass if he didn't hear any more, so I ignored it and didn't react at all if he said it.
If you think about it, there's no point making an issue over something when the child, himself, can't understand more than, say, "a new word that makes adults look worried". It's no different than the "smacking-mom's-face" stage, the "pulling mom's-hair" stage, or the "crying-when-mom-leaves" stage. I'd ignore it for awhile; and if it became too persistent I'd calmly say (without showing any reaction or emotion, and in a low, "somber-ish", voice,) (each time), "No. That's not nice." Without fanfare, emotion, or much of a reaction, it will pass.
Once they're old enough to understand, all you have to do is calmly say, "That isn't nice talk, and we're not having it."