> For the complete documentation index, see [llms.txt](https://docs.bdb.ai/data-science-lab-4/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bdb.ai/data-science-lab-4/project/tabs-for-a-data-science-lab-project/tabs-for-pyspark-environment/notebook/notebook-page/notebook-cells/using-a-code-cell.md).

# Using a Code Cell

Write & Run Code in a Notebook.

You can write and execute code using the Notebook interface. This section covers the steps to write and run a sample code in the Code cell of the Data Science Notebook.

{% hint style="success" %}
*Check out the given walk-through on how to use a Code Cell under a Notebook.*
{% endhint %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FIzsn2WXmh40i2JENdKKX%2FCode%20cell%20(PySpark).mp4?alt=media&token=a14845d6-e838-4e35-9f0d-83a94f89545a>" %}
***Running a Code cell with a code***
{% endembed %}

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> A Code cell gets added by default while creating a new Notebook.*&#x20;
{% endhint %}

## Running Code inside a Code Cell

* Create a new Notebook and open it.
* A cell to write and execute code gets added under the selected Notebook by default.

<figure><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/flaFaCzfKY8MOjECqxhY/image.png" alt=""><figcaption><p><em><strong>Accessing a Code cell within the Notebook interface</strong></em></p></figcaption></figure>

* Write code inside the cell.
* Click the ***Run cell*** icon to run the code.

<figure><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/iXDxveLv0AK6la70Wo6N/image.png" alt=""><figcaption><p><em><strong>Using Run cell icon after inserting relevant code in the Code cell</strong></em></p></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> The Code cells also get code from the selected Notebook operations by using the right-side panel and selecting a specific option. E.g., The user can use the Datasets tab to get an added data set to the code cell.*

{% endhint %}

* The ***Run cell*** button gets changed into the ***Interrupt cell*** icon while running the code.
* Another code cell gets added below (as shown in the following image).

<figure><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/oPvHwIza6MAf1QShBDOA/image.png" alt=""><figcaption></figcaption></figure>

* Once the code has run successfully a checkmark appears below the ***Run cell*** icon.
* The code result gets displayed below it.
* Click the ***Save*** icon provided for the Notebook.

<figure><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/EtcSXQPRTCZSmreQvQly/image.png" alt=""><figcaption></figcaption></figure>

* A notification message appears to indicate the completion of the action.
* The Notebook status gets changed as saved and the new updates get saved in it.

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*

* *The **+Code** and **+Markdown** options provided at the bottom of a cell inserts a new cell after the given code/ Markdown cell.*    &#x20;
* *Refer the **Data Science Lab Quick Start Flow** page to get an overview of the **Data Science Lab** module in nutshell.*&#x20;
  {% endhint %}

## ​Various Options provided to a Code Cell

By clicking on an inserted Code cell, some code related options get displayed as shown in the below-given image:

<figure><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/f74zwHALUdtRIpSRsY23/image.png" alt=""><figcaption></figcaption></figure>

<table><thead><tr><th width="85">Sl. No.</th><th width="98">Icon </th><th width="203">Name</th><th>Action</th></tr></thead><tbody><tr><td>1</td><td><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/vyoJIezJDdvUkL0i3mrx/image.png" alt=""></td><td>Move the cell up</td><td>Moves the cell upwards</td></tr><tr><td>2</td><td><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/SMJW4moToNpEIDinCv2h/image.png" alt=""></td><td>Move the cell down</td><td>Moves the cell downwards</td></tr><tr><td>3</td><td><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/WLGUtmiSqQZUz1wRIkD2/image.png" alt=""></td><td>Delete Cell</td><td>Deletes the code cell.</td></tr></tbody></table>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>* *Refer the* [***Data Science Lab Quick Start Flow***](https://docs.bdb.ai/data-science-lab-4/data-science-lab-quick-start-flow) *page to get an overview of the **Data Science Lab** module in nutshell.*&#x20;
{% endhint %}
