How To Fix Keyboard Type Problems
Macs normally have one of three different physical keyboard "types," which Apple calls JIS (for Japan), ISO (used in Europe, the Middle East, and Africa) and ANSI (used in the US, Latin America, and Asia).
ISO has one key more than ANSI -- located at the left end of the bottom row -- and a vertical (instead of horizontal) Enter key. JIS has quite a few differences from either of those.
Sometimes a machine will forget which type keyboard is attached, with the result that certain keys get transposed from what the user expects. Most commonly this affects the key just below ESC and the key to the right of Left Shift.
Apple's instructions for fixing this are at
Specify a keyboard type on Mac - Apple Support
Sometimes the Keyboard Setup Assistant does not appear or do what is necessary. In that case, you can try the following:
Manually trash this file:
/Library/Preferences/com.apple.keyboardtype.plist
(Note that this is in the Library folder, not System/Library and not Users/username/Library)
This can also be done by opening Terminal and typing (or pasting from here):
sudo rm /Library/Preferences/com.apple.keyboardtype.plist
Run the Setup Assistant:
System Settings > Keyboard > Change Keyboardtype
This can also be done from Terminal
sudo open /System/Library/CoreServices/KeyboardSetupAssistant.app/Contents/MacOS/KeyboardSetupAssistant
It normally then tells you to click on the key to the right of Left Shift. If that does not work, go through the process again and try clicking on the key under ESC instead, or the first key beyond the key to the right of Left Shift.
Choose the type -- ISO, ANSI, or JIS -- which fits your physical keyboard
If nothing above fixes your problem:
Download Karabiner Elements, which has the ability to switch keyboard types (try choosing ANSI if your keyboard is ISO and vice versa) and can also switch the two keys at the left corners of the keyboard which are not working correctly.