When you first set up your Mac, or at least create your user account, you'll be prompted to choose a password. If you tie your Mac account to your iCloud, online Apple account, both passwords will be the same. But you can change each of those passwords at any time, independently from one each other!
Click on the Apple icon (top left corner), and select System Preferences.
From the System Preferences window that opened, click on the "Users & Groups" button, near the bottom left corner. Tip: in that window, you can quickly locate options by typing a keyword in the search box in the top right corner (in this case, you could just type "password" and pick the top result!)
In the next screen, select your user name on the left. The user as which you are currently logged in will be shown at the top - others are listed alphabetically.
Now click on the Change Password button on the right. If your iMac / MacBook password doesn't match iCloud account's, you'll get a "Would you like to change the password for [...], or begin using your iCloud password to log in and unlock this Mac" popup. Click Use iCloud Password to use your Apple account's password as Mac password. Otherwise, click Change Password.
Type your current password first: this security feature prevents others from changing your password in case you leave your Mac unattended! Type your new password - twice, to avoid typos. To avoid being locked out if you forget it, pick a password hint that will help you (and you alone!) remember it. Click Change Password once more, and close the System Preferences window.