How to restore Mac OS after installing Linux
Solution 1:
To answer the questions asked, yes.
However, have a look at How to reinstall macOS and About macOS Recovery.
That said, personally I'd create a USB macOS Installer and set it aside for when you want to reinstall. Have a look at: How to create a bootable installer for macOS
Also, dont forget to make proper backups of your data before formatting the HDD/SSD. You might even want to have a Time Machine backup. Have a look at: How to use Time Machine to back up or restore your Mac