I've stumbled upon a great plug-in called "Remove empty layers", developed by @Germán Carrillo.
I'm wondering if it's possible to use this plug-in in the Python Console.
Yes. It is possible using the following lines.
from RemoveEmptyLayers.removeemptylayers import RemoveEmptyLayers
remove = RemoveEmptyLayers(iface)
Please also check this answer to understand what all
removeemptylayers phrases mean.