> For the complete documentation index, see [llms.txt](https://docs.bdb.ai/data-science-lab-3/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-3/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://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FDRw6QFEsTp077JWG2NHf%2Fimage.png?alt=media&amp;token=a28053cc-7de4-4174-9174-4bfccda5593d" 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://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2F5GW8MW8GaYTTQDgOmXxk%2Fimage.png?alt=media&amp;token=e5c08067-1f2a-4b3b-843a-03effab90da3" 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://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FVIzsxUXi6T90CtTngaWU%2Fimage.png?alt=media&amp;token=3d0960eb-20e0-43c4-a793-9e2f906d84a5" 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://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2F2wqGIP8ckwUekTBMoolZ%2Fimage.png?alt=media&amp;token=b4a144db-fe8c-4670-a45b-4f1c053881f1" 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://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2F3Nod9ZEhV298CwnHR8P1%2Fimage.png?alt=media&amp;token=d6ec4eb0-05ae-4c5a-bd1b-a5640a5039b9" 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://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FlBv84EofqwEbk49ipwI2%2Fimage.png?alt=media&amp;token=e9ef891c-75e0-4ba0-8b07-f4a993784e06" alt=""></td><td>Move the cell up</td><td>Moves the cell upwards</td></tr><tr><td>2</td><td><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FaCH4TwC7sHpHN93Ui3kx%2Fimage.png?alt=media&amp;token=e87428bd-7caa-4b98-be68-64022f81a92c" alt=""></td><td>Move the cell down</td><td>Moves the cell downwards</td></tr><tr><td>3</td><td><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2Fl4NkoNoUwx5nHpbiohu0%2Fimage.png?alt=media&amp;token=f91f25c5-4816-4636-a48f-670ae58c2074" 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-3/data-science-lab-quick-start-flow)*page to get an overview of the **Data Science Lab** module in nutshell.*&#x20;
{% endhint %}
