Example of Cell Magic Functions
1. %%bash
Allows user to run Bash shell commands within the cell.
Example:
Python3
% % bash ls - l |
Output Screenshot:
2. %%html
This cell magic function renders contents of code cell as html script
Example:
Python3
% % html <font size = 10 color = 'hotpink' >Hello World< / font> |
Output Screenshot:
3. %%javascript or %%js
Allows you to execute JavaScript code within the cell
Example:
Python3
% % javascript alert( "This is a JavaScript alert!" ) |
Output Screenshot:
4. %%latex
Renders LaTeX equations and expressions in the cell.
Python3
% % latex $e^{i\pi} + 1 = 0 $ |
Output Screenshot:
5. %%markdown or %%md
Renders the content of the cell as Markdown
Example:
Python3
% % markdown # This is a Markdown Heading * This is a bullet point |
Output Screenshot:
Useful IPython magic commands
In this article, we will cover IPython Magic commands/functions and discuss various types of magic commands available. In this article we will be using Jupyter Notebook to execute the magic commands first, we look at what are Magic functions and why we use them, then different types of magic functions followed by examples. There are a lot of magic functions but in this article, we discuss the most commonly used magic functions.
Jupyter Notebook
The Jupyter Notebook is the original web application for creating and sharing computational documents that contain live code, equations, visualizations, and narrative text. It offers a simple, streamlined, document-centric experience. Jupyter has support for over 40 different programming languages and Python is one of them.