I’m not sure which kind of animals you are talking about. There are some diseases where you get an extra X or an extra Y from your parents accidentally and then you might not have a standard sex. There are also whole species of single-cell animals like ameobas that don’t have sexes, they just split and then there are two of them with all the same genes! But I am guessing probably you mean things like earthworms that are hermaphordites — they can be kind of boys & girls at the same time. Every worm has both sperm & eggs, and when they have sex they both give each other sperm & fertilise each other’s eggs. But if that’s what you mean, I don’t know the answer to your question! I’m not sure whether animals as different from us as worms have X & Y like we do. I know some social insects don’t even split all their genes in half — the females get to have more of their genes in the babies. In general, the definition of “female” is to have a bigger gamete — the two half cells that are brought together, which ever is bigger is called an “egg” and the other is called the “sperm”, and the one with the eggs is called female. I also know there are some species of fish that only have females, and they just lay eggs that make more females.
In mammals, the gender is determined by the sex chromosomes (we call them X andY). Males have one X (from the mother) and one Y (from the father) and females have two X (one from each parent). In mammals, it is possible to get rare mutations, for example an individual may have three sex chromosomes.
In many species, sex is determined in different ways, by different chromosomes, so the gender is not determined by the chromosomes the parents give. For example aphids are asexual (neither male nor female) most of the time, so a baby is a clone of their parent, and then occasionally change and become either male or female. So some aphids have one parent,some have two! Many fish change their gender, and start life as female, and then when they grow big, become male.