Swearing is used as a verbal relief from stress or pain. The actual words used vary widely according to the culture in which it is used, but they usually refer to something that the majority of local people think of as a taboo subject. Most of them therefore relate to sex, genitals, excretion, or religion.
Despite widespread condemnation by the more highly moralising adults of the day, swearing is completely harmless, and has a number of uses apart from the mere venting of frustration. Adults refrain from using it in a fairly feeble attempt to assert their maturity over teenagers and children. Teenagers use it to rebel, and children use it to get attention. Characters in films, on the other hand, tend to use it for comic relief.