I'm going to buy my first DSLR camera mainly for astrophotography and some panoramic photography. I will probably buy the Nikon D3500 but I don't understand why the Canon T7 is more expensive than the Nikon even if the Nikon has the best specs, I compared the 2 camera on CameraDecision and the Canon only had a few features the Nikon don't have. Which is the best for long exposure and low light?
For astrophotography, you'll be looking at low light performance. That requires a good fast lens (usually a prime), and the ability to have actually useful high ISO. The specs mention neither. The high ISO on Nikon might suggest the Nikon is better, but the high ISO could be just so noisy that it's useless.
So, back to the researching stage: what is your budget for an astrophotography lens and does the Canon APS-C or Nikon APS-C system have that lens?
You should also find some review where the low-light performance of the cameras are compared. Look at the level of noise in high ISO images.
Normally I'd respond to questions like this with, "Buy either one. They're both good enough."
But for astro work, there probably are at least three considerations you should be aware of. This is particularly the case since you have said in a comment that you are planning on using it with a 12 inch telescope, which usually means deep sky work rather than very wide field landscape astrophotography.
The first is called the "star eater" problem. Basically, all digital cameras do some noise reduction in the analog stage of collecting the information captured by the camera's sensor. This can not be controlled or turned on/off by the end user like noise reduction done to the data after it has been converted to digital information can. Some sensors and brands do this more extensively than others. Those that do it more aggressively sometimes eliminate weaker stars along with actual image noise. Thus, some folks say the camera "eats stars."
The worst offenders have historically been Sony cameras and Nikon cameras that use Sony sensors. Canon tends to be the least offensive because they do minimal on-die noise reduction and leave it to the user to decide how much and how to apply noise reduction to the digital image information in post-processing. Nikon cameras that do not use Sony sensors tend to be somewhere in between.
Some folks¹ claim Sony has "fixed" the star eater problem, others disagree and claim that it's not as bad as it once was, but there are still issues with green and magenta color shifts on "single pixel" and "two pixel" stars.
So you might want to google around and see where the D3500 and T7 fall in this regard.
The other is sensitivity to Hydrogen alpha emissions at 656.28nm that are heavily attenuated by the IR filter included in the stack of filters in front of the imaging sensors with pretty much all "regular" DSLRs. Hα makes up a large part of the energy that reaches the Earth from nebulae and other deep sky objects that contain a lot of dust.
There have been a few cameras offered by manufacturers with modified sensor stacks that allow Hα to pass through unimpeded. The Nikon D810a and Canon 60a are probably two of the most well known. One can also take a "regular" DSLR or mirrorless camera and send it to a third party specialist company, such as Lifepixel.com, and they will modify the sensor stack by replacing the standard IR filter with one that allows Hα through.
Unfortunately, a camera sensitive to Hα is not very useful for types of photography other than astro work.
One other thing you might want to think about is the suitability of an APS-C sensor vs. a FF one. With about 2.25X more light gathering ability than an APS-C sensor, a FF camera can make a real difference in imaging dim astronomical objects.
Rather than buying either a new T7 or D3500, perhaps you should consider a lightly used older full frame camera, such as a Canon 5D Mark II that can be had in relatively good condition for around $400, and having it modified for astro with Hα sensitivity. For astro work my nearly decade old 5D Mark II is just as good as my newer 5D Mark IV. The faster handling, vastly improved autofocus, better dynamic range at base ISO (which you will rarely, if ever, use doing astro) and many other features that the 5D Mark IV offers over the 5D Mark II are totally irrelevant for astro work.
¹ PetaPixel has run numerous articles over the years that basically say "This time it really has been fixed" every time Sony releases a new generation of sensors. Then those doing serious astro work show how the issue is still present to some extent with those sensors. Fast forward to the release of the next generation of Sony sensors when someone writes another PetaPixel article that says "This time it really has been fixed..."
First, your price comparison is not right — as I look on Amazon and B&H Photo right now, both are right below $400, with a three dollar price advantage for the Nikon camera. That's not a difference to make a big deal of.
Second, these automatic comparison sites are terrible. They don't use any human judgement and focus on emphasizing nitpicky differences as if they're a big deal. It's better to read a human-written comparison, like this one on DPreview. Like you, they favor the Nikon option slightly, but:
If you tally up the 'points' for the D3500 and you'll see how we drew our conclusion that it's the better pick between the two. However, the two cameras are incredibly similar in most ways, so it's really only details like a nicer 18-55mm kit lens and incredibly robust battery life that tip the scale.
For astrophotography with a telescope as the lens, I'm not sure either of those really matters. You won't be using the lens, and tossing in a few extra batteries is trivial. So, go for the one you're most attracted to — or better yet, the system you're most interested in. (See Is there any significant difference between Nikon and Canon?.) Both cameras are amazing for the price, so you really can't go wrong.
One suggestion, though: since you're not going to use the kit lens, consider not buying it. For about $100-$150 more, you can go up a step in either the Nikon or Canon lineup and get a camera sold "body only" that's somewhat better in specifications.
Note that neither of these cameras is officially sold in the US market as "body only". If you find it offered that way, you are in the "grey market". This may be a camera meant for a different country, which means you may be trouble getting US warranty service. Or it may be that an dubious vendor has taken the official "kit" apart and is selling the camera separately. In either case, I'd avoid that.
If you do decide to go up a notice, you may also want to check for a Pentax DSLR in that price range — Pentax is the third big-name maker of DSLR cameras, and they have in-body image stabilization and a unique "astrotracer" feature.