Press Q. The screen locks and shows the login picture; Touch ID or the password unlocks it. The same command is under the Apple menu at the top left as Lock Screen.

Closing a MacBook's lid sleeps it, and the lock follows from a setting: System Settings → Lock Screen → "Require password after screen saver begins or display is turned off". A new Mac often has a five-minute grace period there; set it to Immediately if the Mac leaves the house.

A hot corner can lock too: System Settings → Desktop & Dock → Hot Corners → Lock Screen, then push the pointer into that corner.