In most cases, yes. However, it will not help if your backup, the recovery partition, or other devices are infected. Also, resetting the Mac will not help if it was infected with a rootkit that enables administrator-level access to your device.