Minecraft wiki entry for Formatting_codes, associated text: To enter "§" on Windows with most US/UK English keyboards type Alt + NUMPAD2NUMPAD1 (alt code on cp437). For any other keyboard, the Windows ANSI version Alt + NUMPAD0NUMPAD1NUMPAD6NUMPAD7 often works.
If EnableHexNumpad is enabled in the Windows registry, Alt + NUMPAD+ANUMPAD7 (using the main keyboard for "A") works for any language due to it being Unicode.
On a Mac with a US keyboard, type ⌥ Option + 6 (or ⌥ Option + 5 for US Extended). For any other keyboard, type ⌥ Option + 00a7.
On Linux with the compose key activated, type Composeso. The symbol can also be typed by using Unicode shortcuts: Ctrl + ⇧ Shift + u00a7.
To enter "§" on a Nintendo Switch, select languages (globe icon), scroll to the bottom to find the "Symbols" language, and then select Page 2 to find the symbol to the right in the bottom line.
For various Android keyboards:
Google Keyboard (GBoard): The "§" is under the paragraph "¶" mark. To access, tap the number/symbol button, tap button above "ABC" to access more symbols, then hold down the paragraph key.
Samsung Keyboard: The "§" is under the "s" key. To access, hold down on the "s" and then slide over to the "§" mark.
For iOS:
On the iPad the "§" is under the percent sign. To access, tap the number/symbol button and then swipe down on the percent sign.
On the iPhone the "§" is under the ampersand "&". To access, tap the number/symbol button then hold down the ampersand key and slide over to the "§" mark.
For Xbox:
On the Xbox One the "§" is under the backward P "¶". To access, use the left trigger, hold down A while on ¶ until other options pop up. Move the cursor over to the "§" mark and use A to select.