As other answers have noted, these are examples of puns.
The pun, also called paronomasia, is a form of word play which
suggests two or more meanings, by exploiting multiple meanings of
words, or of similar-sounding words, for an intended humorous or
rhetorical effect. These ambiguities can arise from the intentional
use and abuse of homophonic, homographic, metonymic, or metaphorical
But what sort of puns? The Reader's Digest condensed version ("What's that?") of the Wikipedia article may help us decide:
Puns can be classified in various ways:
The homophonic pun, a common type, uses word pairs which sound alike
(homophones) but are not synonymous. For example, in George Carlin's
phrase "Atheism is a non-prophet institution", the word "prophet" is
put in place of its homophone "profit", altering the common phrase
A homographic pun exploits words which are spelled the same
(homographs) but possess different meanings and sounds. Because of
their nature, they rely on sight more than hearing, contrary to
homophonic puns. An example which combines homophonic and homographic
punning is Douglas Adams's line "You can tune a guitar, but you can't
tuna fish. Unless of course, you play bass."
Homonymic puns, another common type, arise from the exploitation of
words which are both homographs and homophones. The statement "Being
in politics is just like playing golf: you are trapped in one bad lie
after another" puns on the two meanings of the word lie as "a
deliberate untruth" and as "the position in which something rests".
A compound pun is a statement that contains two or more puns. For
example, a complex statement by Richard Whately includes four puns:
"Why can a man never starve in the Great Desert? Because he can eat
the sand which is there. But what brought the sandwiches there? Why,
Noah sent Ham, and his descendants mustered and bred." This pun uses
"sand which is there/sandwiches there, "Ham/ham", "mustered/mustard",
and "bred/bread". Compound puns may also combine two phrases that
share a word. For example, "Where do mathematicians go on weekends? To
a Möbius strip club!" puns on Möbius strip and strip club.
A recursive pun is one in which the second aspect of a pun relies on
the understanding of an element in the first. For example the
statement "π is only half a pie." (π radians is 180 degrees, or half a
circle, and a pie is a complete circle). Another example is "Infinity
is not in finity," which means infinity is not in finite range.
Another example is "A Freudian slip is when you say one thing but mean
your mother." Finally, we are given "Immanuel doesn't pun, he Kant" by