By default, when I close the lid of my macbook, the external display becomes the primary. It is annoying because I have to plug out the cable and charger to turn it off but I'd like that whenever I close the lid of my macbook, it puts the macbook to sleep and turns off external display? Is it possible?
As macOS doesn't provide a way to shutdown all screens by closing the laptop lead, which is a shame, you can put the laptop in sleep mode and also set security parameter to lock it immediately when it goes to sleep so you can leave once the screen is black.
I put it on the left to be sure not to touch it when i hit the fingerprint sensor or the delete key...
To modify the touch bar, go to system preferences/keyboard and you will find a "customise touchbar" on the bottom right corner.
Putting the MacBook to sleep by using the mouse to select the "apple icon" in the (drop down) menu in Finder, and then select "Sleep" should turn off the external display.
I use a MacBook with a MiniDisplay Port and USB monitors. I have the same behaviour as you when I close the MacBook. But when I put the MacBook to sleep via the drop down menu, all the monitors turn off.
If you have an external keyboard connected, you can try pressing CMD-Brightness Up. If you don't have an external keyboard connected, you can press the power button on your display (if it has one). If those don't work you'll have to: Unplug the HDMI/Thunderbolt cable going to the display from your Mac. Unplug the power adapter from your Mac. Shut down your Mac. Change the input on your display (if available).
Command+brightness DOWN is what you need to press.
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.