When was it first discovered (or comprehended) that air has weight? Did the ancients know of this, or did they think that air is weightless?
There is a subtle difference between realizing that air is a substance (as opposed to a void) and establishing that is has weight, see also Who was the first to postulate that space was a vacuum? for a related issue. The former was demonstrated by Empedocles (c. 490–430 BC) by using perhaps one of the first experimental apparatuses in history, a glass tube called hydra. Here is from Close's The Void:
"If you place your finger over it no water flows. If you empty the water from the hydra and then submerge it water will pour in and refill it as long as the open end remains open. However, if the end is covered with your finger no water enters the holes, and no air escapes either. This demonstrated that air and water coexist in the same space; no water can enter until the air leaves; air is a substance and not empty space."
However, fire was also considered a substance, but a weightless one. Aristotle describes another experiment, with an inflated bladder, upon which his belief in air's weight was based in De Caelo [On the Heavens] Book IV.4:
"Earth, then, and bodies in which earth preponderates, must needs have weight everywhere, while water is heavy anywhere but in earth, and air is heavy when not in water or earth. In its own place each of these bodies has weight excepting fire, even air. Of this we have evidence in the fact that a bladder when inflated weighs more than when empty".
Aristotle's view was more or less accepted during the middle ages. But this might have been a case of believing the right thing for the wrong reasons, a historical instance of what is now called the Gettier problem of knowledge. Galileo was skeptical:
"I am inclined to believe that the increase of weight observed in the leather bottle or bladder arises, not from the gravity of the air, but from the many thick vapors mingled with it in these lower regions. To this I would attribute the increase in weight in the leather bottle."
Modern considerations also cast doubt on the validity of the bladder experiment, so if we exclude Gettierfied "knowledge" Galileo might have been the first to establish that air has weight, and measure it. A good historical survey of this topic is West's Torricelli and the Ocean of Air:
"It is interesting that, today, teachers of elementary physics often use an experiment with an inflated balloon to make the point that air has weight. There are several examples of these on the internet. In a typical demonstration, two inflated toy balloons are suspended at the ends of a long stick such as a meter rule, and this is supported in the middle so that it is balanced. One balloon is then burst by putting a match under it, and the other balloon tilts the balance downward.
In fact, this is a misleading demonstration because the reason why the intact balloon falls is that it contains air under pressure. If the two balloons are inflated with air at normal atmospheric pressure, deflating one balloon will not change the balance. The reason is that a balloon at normal pressure, such as a thin plastic bag that has been partly inflated, receives support by buoyancy from the air around it, which cancels the weight of the air inside it.
Galileo presumably understood this, although he does not appear to state it. What he does do is describe in detail a method for measuring the weight of the air. This is included in Discourses Concerning Two New Sciences."
Since ancient times, air was considered one of the four elements (air, water, fire, earth). As Aristotle said in De Cœlo II, ch. 13 (294b ):
air is lighter than water, so is water than earth
In De Cœlo IV, ch. 4 (311b), he says:
air is heavy when not in water or earth
So, he certainly believes air has some gravity.
The fact that air has weight was first well comprehended by Torricelli.
In ancient times people used to explain water suction through a pipe by assuming Nature has horror to vacuum. There is however two objections to this idea. Gasparo Berti in 1640's created a stable vacuum by submerging the open end of a tube previously filled with water (a barometer), showing that Nature does not have horror to vacuum. Second, there was a practical problem that drew the attention of many people at that time: How to suck water through a pipe to a height greater than $10\, m$? Galileo himself proposed a solution by simply saying that the water column breaks down under its own weight when it reaches $10\, m$ tall.
Evangelista Torricelli was the first to explain both phenomena above. He assumed that air has weight and we live at the "bottom of an ocean". The pressure due to air weight matches the pressure due to the liquid in the pipe. Therefore the maximum pressure the atmosphere can generate equals the pressure due to a $10\, m$ tall column of water. Torricelli then predicted that tallest column of Mercury would be $0.76\, m$, since Mercury is $13.6$ times denser than water, and that was later confirmed by his colleague Vicenzo Viviani.