Learn practical skills, build real-world projects, and advance your career

Jupyter Notebook Magic Commands

This notebook is part of my Medium article on the '6 Magic Commands That Every Data Wizard Should Know'. The following examples demonstrate the top 6 magic commands that you need to know when you're working in a Jupyter Notebook.

There are 2 types of magic commands: % prefix and %% prefix. 
The % prefix indicates that the command runs over a single line of code whereas %% prefix allows the command to runs over an entire cell. Don't worry, you'll see the difference between these two in the following examples.

1. %lsmagic

The %lsmagic command will list all the magic commands that we can use in Jupyter Notebook.

%lsmagic

2. %%writefile

The %writefile command allows you to export your cell's content into an external file. If the file already existed, it will overwrite the original content of the file with the exported cell's content.

%%writefile hello.py

def say_hello():
    print("Hello!")