To comment out multiple lines in a Databricks notebook, you can use the following methods depending on the type of code you are working with:
Python or Scala Code
- Select the lines of code that you want to comment out.
- Use the shortcut:
- For Windows/Linux: Press
Ctrl + /
- For Mac: Press
Cmd + /
- For Windows/Linux: Press
This will add a #
symbol at the beginning of each selected line, effectively commenting them out.
SQL Code
For SQL code, you can use bracketed comments to comment out multiple lines:
- Bracketed Comments: Use
/*
to start the comment and*/
to end the comment. This can span multiple lines.
Example:
sql
/*
SELECT * FROM database.tablename
WHERE condition
*/
This method is useful for temporarily disabling sections of SQL code without deleting them.
Additional Shortcuts
- Uncommenting: To uncomment the selected text, you can use
Ctrl + U
(orCmd + U
on Mac) after selecting the commented lines.