How to Show Line Numbers in Jupyter Notebook

Do you want to show line numbers in Jupyter Notebook ? If yes then you have come to the right place. In this tutorial you will know how to show line numbers in Jupyter Notebook.

Methods to show line numbers in Jupyter Notebook

Method 1: Esc key with “L” key

The first method is to first use the “Esc” key to enter the cursor in command mode. After that press the “L” key to show the line numbers.

You will show line number to single cell only using the Esc and L key. If you want to show line numbers to all the cells then you will use the Esc and “Shift + L“.

SPECIAL OFFER!

This Offer is Limited! Grab your Discount!
15000 ChatGPT Prompts
Offer Expires In:

Method 2: Use the Command Palette

The second method is the use of Command Palette. Here you will first press the “Ctrl+Shift+P” on windows or “Cmd+Shift+P” on MacOS. It will open the command palette. After that type line numbers in search field. Just click on toggle all line numbers to show the line numbers for all cells.

Method 3: Show line numbers in Jupyter Notebook through Top Menu

You can also use the Top menu of the Jupyter Notebook to view the line numbers.

You have to just click the view on the top menu and after that click Toggle Line Numbers to show the line numbers to cells.

Method 4: Set the default configuration in JupyterLab

You can edit the setting to show line numbers if you are using JupyterLab.

Just click on the setting and click on Advanced configuration.

After that click on JSON setting editor that you will see in the top right corner of the Advanced Settings Editor. It will show the User Overrides editor.

Just edit using the below lines of code to show the line numbers.

{
    "codeCellConfig": {
        "lineNumbers": true
    }
}

Method 5: Show line number of Jupyter Notebook for VS Code

If you are using Jupyter Notebbok in VS Code and want to show the line numbers then press the Ctrl+Shift+P (Windows) and Cmd+Shift+P (macOS) to open the command palette.

Type use setting and choose the preferences : Open User Settings. After that type the notebook line numbers and set on to the Notebook: Line Number.

Restart the VS Code after all the changes.

Method 6: Change settings.json

You can also show lines number by changing the settings.json for the VS code. Just add the following dictionary inside the setting object.

"notebook.lineNumbers": "on",

Conlusion

If you are debugging or finding errors inside the code then line number plays an important role. You quickly navigate when the python interpreter shows the error. The above method will allows you to show line numbers in Jupyter Notebook. You can follow any method as per convenience.

SPECIAL OFFER!

This Offer is Limited! Grab your Discount!
15000 ChatGPT Prompts
Offer Expires In:
Hi, I am CodeTheBest. Here you will learn the best coding tutorials on the latest technologies like a flutter, react js, python, Julia, and many more in a single place.

SPECIAL OFFER!

This Offer is Limited! Grab your Discount!
15000 ChatGPT Prompts
Offer Expires In:
close-link