About 4.5 billion years ago a gigantic cloud of gases, minerals, ice and other frozen materials began clumping together to form the sun and planets. Some of those clumps didn't grow large enough to become planets, and became asteroids and comets. In the same way that the planets are quite distinct from each other, comets are also distinct. You can't say what the temperature of a planet is, because they are all so different. For instance, the sunny side of Mercury is much hotter than the shady side of Neptune. The temperature of a comet varies wildly based on where it is in its orbit.
Asteroids and comets are different from each other, but the biggest difference -- the one responsible for all the other differences -- is that they have much different orbits. Asteroids are in orbits more or less like the larger planets -- almost in a circle around the sun. Cometary orbits are nowhere near circular. They are very stretched out ellipses. That means comets start out very far away from the sun and then zip in close to it. But their orbits are so large that they don't make that circuit very often. There are two classes of comets. Short-period comets orbit the sun over a period of less than 200 years. Long-period comets circle the sun much more slowly, taking more -- sometimes much more -- than 200 years to circle the sun.
The further an object is from the sun, the more slowly it moves. Earth orbits the sun in one year, for example, while Jupiter takes about 12 years to do so. The orbits of comets have both parts: a section where they zoom very close to the sun and a section where they hang out much further away than any planet. Because objects move slower further from the sun, this means that comets will zip by the sun in a few months -- or even more quickly -- and then stay far away from it for decades, centuries or even thousands of years. So most of the time, the comets are far away from the sun. There are two main regions where comets hang out. The Kuiper Belt is a region beyond the orbit of Neptune, from about 30 to about 50 times further from the sun than the Earth's orbit. The Oort Cloud is much further away -- about 50,000 times further from the sun than the Earth's orbit. Short period comets come from the Kuiper Belt and long period comets come from the Oort Cloud.
Although comets are different from one another, there appear to be some similarities among all comets. They have a solid core, but that core appears to be a mix of minerals and volatiles -- compounds that would evaporate if they were on the Earth. When a comet comes close to the sun, it warms up and some of those compounds shoot off its surface. That creates two regions called the coma and the tail. The coma is the part of the comet closest to the sun, and can be described as a cushion of gas surrounding a solid core. The tail is a long streamer created when those volatile gases get pushed away by the solar wind, so it points more or less away from the sun.
If you've ever gone camping, you know that the heat of a campfire doesn't go very far. When you're right next to it, you feel hot, but if you're fifty yards away you aren't warmed up at all. If you move five hundred yards away you're ten times further from the fire, but you don't really notice that you're any colder because you were already so far it wasn't warming you. That's the same story with comets in the Kuiper Belt and the Oort Cloud. Even though the Oort Cloud is much further, comets way out in both regions are at temperatures of about -220 degrees Celsius (-364 degrees Fahrenheit). Of course,, if you sit around the fire, you are warm. But if you stick your hand in the fire, you burn yourself. That's the same thing comets can do. Some just zip by close to the sun, but some come so close they actually go through the sun's outer atmosphere. Those comets are called sungrazers, and their surfaces heat up to millions of degrees when they shoot that close to the sun. So when comets make their wild ride around the sun, they go through an equally wild temperature swing.