The way to lock your computer on a Mac is a rather long winded one in theory. What you need to do is put your display to sleep, and then through the security section of the system preferences window, set your Mac to ask you for a password by after the screen saver begins.
To do so, it'll be convenient to create an active corner for a putting your display to sleep first. Follow this tutorial if you need help on how to do so, and set the option for "Put display to sleep" to a particular corner of your choice. Then open system preferences again, and click on Security. Check the box that says "Require a password ______ after sleep or screen saver begins". For the time option, I usually use five seconds, in case I accidentally trigger the active screen corner, putting my display to sleep and locking my computer.
And you're done. When you need to lock your computer, just move your mouse to the screen corner that you set and walk away from your computer (only for a short time I hope) knowing that it is safe from prying eyes. Plus, you are saving energy, as insignificant as it may seem, and helping the environment.
Got a question, tip or comment? Send them to email@example.com and we'll try to answer it in a blog post!