Yoga (if you limit its practice to asanas/pranayama) and gym are both forms of exercise that offer different benefits. It's not a matter of one being better than the other, but rather which one better suits your individual needs and preferences.
Yoga is a holistic practice that focuses on the mind, body, and breath. It can help to improve flexibility, balance, and strength, as well as reduce stress and anxiety. Yoga can also help to improve focus and concentration, and many people find that it has a calming and grounding effect on the mind.
Gym, on the other hand, typically involves using equipment and weights to build muscle and strength, and can be a good choice for those looking to improve their cardiovascular health or build muscle mass. It also provides a variety of options for workout like cardio, strength, weight training, and HIIT etc.
Both yoga and gym can be effective forms of exercise, but which one you choose will depend on your individual goals and preferences. It's also possible to combine both yoga and gym to get the best of both worlds.
It's best to consult a fitness expert or a doctor to know what would be the best for you, especially if you have any pre-existing condition.