Gases are compressible and fill the available space:
* Expansion: Gases have very weak intermolecular forces holding them together, allowing them to spread out and occupy the entire volume of their container. This means they will expand to fill any space available, including the space above the liquid in the container.
* Air is a gas: The air around us is a mixture of gases, primarily nitrogen and oxygen. This air is always present, and it will always be present in the space above the liquid in a container.
* Mixing: Some gases can dissolve into the liquid, especially at higher pressures. This is why opening a bottle of soda makes it fizz; the dissolved carbon dioxide gas comes out of solution and forms bubbles.
So, it's not really about the gas "filling" the container, but rather about it occupying the space above the liquid. This is a fundamental property of gases and how they behave.