How to Comment Multiple Lines in a Databricks Notebook
Here’s how to comment out multiple lines in a Databricks notebook, depending on the type of code:
Python or Scala Code
- Highlight the lines you want to comment.
- Use these shortcuts:
- Windows/Linux: Press
Ctrl + /
- Mac: Press
Cmd + /
This adds a
#
at the start of each selected line. - Windows/Linux: Press
SQL Code
- Use bracketed comments to comment out multiple lines:
- Start with
/*
and end with*/
. - Example:
sql
/*
SELECT * FROM database.tablename
WHERE condition
*/
- This temporarily disables the code without deleting it.
- Start with
Uncommenting
- To uncomment, select the commented lines and press
Ctrl + U
(orCmd + U
on Mac).