Sexing cannabis plants can seem tricky, but with a little know-how it really is quite simple. There are a number of reasons you want to be able to tell the sex of a cannabis plant, breeding, growing out regular cannabis seeds and most importantly removing any males from your growing area before they pollinate your female plants. Pollinated bud will divert its energy away from THC production and focus on creating seeds. Sometimes plants will hermie, this can be down to a number of factors, ill cover them in another topic. Hermie means a plant will produce pollen sacks, even if 100% female, should this happen a female plant will produce seeds, the bud will still be smokeable but wont be anything like it should be.
To learn more about how and why a plant would hermie follow this link:
viewtopic.php?f=6&t=120
Paying close attention to your flowering plants is the only way to know the sex of them, there can be tell tale signs before the plant shows sex, males tend to be more stretchy, females more squat and leafy, but this is not a safe way to guess, given the many strains and crosses these characteristics can be down to genetics.
To induce Flowering we need to mimic a plants natural life cycle, we do this by providing 12 hours of light and 12 hours of dark. This replicates summer is coming to an end, plants are living things and all living things need to reproduce. Once a cannabis plant thinks summer is coming to an end it is driven to reproduce, to do so it needs to form the necessary parts to do, showing its sex.
Autoflowering plants are different, they don't use light cycles to dictate their life cycle, follow the link to learn more about autoflowering cannabis plants:
viewtopic.php?f=25&t=95
Male pre-flowers are very obvious once you know what you are looking for. Males pre-flowers will form where the branches leave the stem, they will look like little balls.

Female pre-flowers will form in the same places as male pre-flowers but look very different. They will produce a pair of white hairs known as pistils.

This is when you need to pay attention and remove any males.