The most common tapeworm of urban dogs and cats is Dipylidium caninum

I labled the adult parasite TW in the diagram above and drew the head portion Sc(scolex) next to it enlarged, so you could see the circle of hooks Rs (rostellum) with which it attaches to your pet's intestinal lining.

From its head to its last segment, this tapeworm is about a foot long.   During its lifespan  the tapeworm only sheds the last segments (Pg1) (proglotids) of its body. Those are the rice-like grains you see on your pet's stool and clinging to its anal region.

The tapeworm looks a bit like a string of pearls - each pearl being a proglottid segment. These segments are not complete living things, they are egg cases that move about on their own for a period of time (until they dry out). Once they have dried out, they look more like sesame seeds. They burst, showering the animal's fur with individual tapeworm egg  packets (EC), each containing about 20 individual eggs.

When your pet also has fleas, there are flea eggs in its fur - particularly around its  rear and tail. I drew five of those flea eggs (Fe). They hatch into larval fleas (FL) on your pets skin where they feed on skin debris. In the process of feeding, these flea larva also eat some of the tapeworm eggs (EC) on your pet. Some flea larva and tapeworm eggs fall off of your pet in areas with nooks and crannies where the pet spends considerable time - places like rugs, sofas, carpeted areas, cracks in wood flooring, baseboards and the like. In those areas, the flea larva also ingest fallen tapeworm eggs. 

Within the flea larva, the tapeworm egg hatches and develops into an intermediate stage (cysticercoid). These persist in this dormant stage while the larva pupate (Fp) and develop into new adult fleas (F).

When pets groom themselves, they eat any fleas they catch. When the dead flea reaches the correct portion of the pet's intestine, the new tapeworm begins to develop and escape, creating a new adult tapeworm.

It takes about a month from the time your pet catches an infected flea, until you see new tapeworm segments (proglottids) on its stool. The proglottids that you see are not infectious to you or your pet. To activate, they must first pass through a flea. So if you pet has no more fleas, it will not contract new tapeworms.  The lifespan of these tapeworms is thought to be about a year.

There are other tapeworms that affect pets, but they are  transmitted by eating raw meat or rodents. I do not see them frequently in the urban pets I treat. But I drew a section of proglottids  (Pg2) that you would seen in the pet's stool if those less common  kinds of tapeworms were the problem.

Occasionally, severe diarrhea will cause pets to expel large portions, or even complete tapeworms. When your veterinarian destroys tapeworms with an injection or tablet, you will not see the dead worms in its stool. They are simply dissolve by the digestive enzymes in your pet's intestines.

D. caninum will grow in humans - if a pet's flea is accidentally eaten. It is an occasional problem in children. You can read a CDC article about that here.