Operant or Skinnerian conditioning is one way that animals can learn tricks. I hope to give you the tools to use it effectively. I have trained chickens to play ping pong, dogs to roll over and my cat to sit, stand and wave.
Let's use a male dog or cat named Spot for the example subject and the trick will be to roll over. Spot needs to be hungry enough to work for a little pellet of pet food or a little pinch of hot dog meat. You can get a bowl of dried pet food and sit in a comfortable chair.
A little noise maker is necessary or you can say "good" each time Spot does what you want. This is to pair the food and the noise together. Do this by throwing a piece of food to Spot right after making the noise. After a few times, Spot will realized that the noise means that he will be getting some food. This is in order to give feedback immediately to Spot during the training that he has just done something that earned some food.
Now we will use the method of approximations to get Spot to roll over. Spot already has had the noise followed by food a few times. He will be paying attention to you and hope for that noise again. We can't get him to roll over all at once so we just start to reward the behavior as it approximates rolling over. Since we also want it on command, we can say "Roll over" and then wait until he makes the slightest move of sitting or laying down. Then make the noise and toss the food reward to Spot. Now say "Roll over" and wait for Spot to sit again or start to lay down a little more than last time. Again the reward is given. After 10 times or less, I think Spot will be laying down very rapidly, and you need to get him to start to roll over so wait until he is laying down and then leaning to one side even a fraction of an inch and give the reward. As you get Spot to lean further and further with each reward, eventually he will be rolling over. You probably can get him to do this within 10 minutes on the first session, but if not, I think you should stop after 10 minutes and resume where you left off on the next day. When I trained my 6 roosters to play ping pong, I would stop after 10 minutes and after 4 sessions each or 40 minutes total per bird they would wait for a ping-pong ball to roll towards them on a table and peck it back to the other side where I had stationed another rooster who did the same. After a while I was only rewarding winning shots that the other bird couldn't return. The force and accuracy that the roosters were using to peck the ball was impressive. The noise maker I used was a little child's whistle and the reward was a few pecks from a jar of chicken food. At the beginning of their sessions, I rewarded them as they moved closer to a ping pong ball in their cage. Within 5 minutes they were putting their beak right on the ball and then they would give it a modest peck and then it was a matter of perfecting their shots.
This basic training system can work on raccoons, squirrels, birds and many other animals. Snakes are difficult because they eat a single large meal and may not eat again for a week. I visited a ward for mentally challenged patients where this system was being used to stop head banging behavior. The head banging was taught to the patients by accident because if they banged their heads, staff would rush to them and try to get them to quit and the attention was the reward. What was being done in this experimental ward was giving the patients a lot of attention and even occasional M Ms; as treats while the patients were not banging their heads. If they banged their head, the patient was rushed to a quiet room where they received no attention until 60 seconds had passed with no head banging and then they were given attention again. The results were dramatic. After 3 trips to the quiet room, hardly any head banging was observed. Unfortunately, when they returned to the regular understaffed wards, they quickly began the head banging again for some attention.
Important things to remember are to make the noise very fast after the behavior is accomplished. You can fumble around with the food reward as long as the animal knows that he already has earned it. The behavior just needs to be the slightest improvement over last time. Don't wait until the animal does the entire trick, which will never happen.