Every parent under the sun goes through this horrible period somewhere between 18 months and 4 years wherein their lovely, sweet, and perfect baby finds out 'potty words' get noticed. I remember a two year old cousin stomping around the room one Christmas singing "Sh*t, Sh*t, Sh*t, Sh*t, Sh*t, Sh*t, Sh*t, Sh*t....." What in the world is a parent to do with this?
Well this just might be the best approach if it seems like an isolated incident of mimicry and development. Very young toddlers will pick up on sounds and words and try them out. Often it is just part of the development of the skills used to incorporate language into their daily lives. New words, fun sounds, and constructions that have a good 'mouth feel' make for common repeated phrases and words. The newly tested word will be abandoned shortly for a new one and your life will move forward.
A side note on this: To this day the phrase, ‘Mecca Lecca High Mecca Hiney Ho!’ plays over and over in my brain.... damn you pee wee herman!
Sometimes that lovely 'mouth feel' of a word can get stuck and becomes a bit of a habit. The little mirrors, that are our children, pick up on some of our worst behaviors. When handled appropriately a simple redirection can accomplish quite a bit of good. Three and four year olds often want to be oppositional and test limits, but, for the most part, like to please their parents. If you can time the discussion correctly (NOT right after the child drops an F*bomb in the grocery store which reinforces the behavior) you can redirect the behavior. It needs to be communicated clearly that their choice to use that word wasn't the right behavior and is dissapointing. This should be done at some time after but not so far down the road they cannot remember the actual behavior. Like maybe in the car on the way home.
At a certain point all kids will do stuff just to push your buttons and the limits of the relationship. It is completely natural and part of their development. You want your child to question the rules in life. You want them to grow and thrive and test the boundaries. How else would we have ever made it to the moon or invented the iPhone or thought to put bacon into a chocolate sundae? HOWEVER, part of pushing boundaries and testing the function of the world is to suffer a few consequences in breaking the "rules". Jumping out of a tree to see if you can fly (ill-advised behavior, by the way) has the consequence of hitting the ground. AND the foul-mouthed kindergarten student is going to have some pretty major consequences for you as a parent and your child too. Set realistic limits and clear consequences of the behavior. Time outs, loss of favorite toy, loss of desert, loss of story time, etc. If all else fails, pull a Lifebouy like poor ole Ralphie.