Yes. If you do it! Regardless of where exercise takes place, you get the full benefit. There are two advantages to exercising at a fitness center. First you are more likely to exercise if you have to pay for the gym. You are also more likely to go to the gym if you set up a regular time to exercise.
Many things can interrupt exercising at home. Since you are by yourself, you aren't as likely to do as much exercise as when there is a class or some other kind of supervision. Finally in a gym or fitness center you'll gain the support you need to stick with the program. If you don't show up, someone may ask, "Where were you? We missed you." This may motivate you to keep coming back even after you miss a day.