<jupyter_start><jupyter_text>Introduction to Notebooks [Cloud Datalab](https://cloud.google.com/datalab) builds on the notebook metaphor popularized by [Jupyter](http://jupyter.org) (formerly known as IPython). If you have used notebooks, you'll find a familiar environment. If you're new to the idea of notebooks, this introduction should cover the basics to get you started.  Notebook Basics  NotebooksA _notebook_ is essentially a source artifact, saved as a .ipynb file - it can contain descriptive text content, executable code blocks, and associated results (rendered as interactive HTML). Structually, a notebook is a sequence of cells.  CellsA _cell_ is a block of input text that is evaluated to produce results. Cells can be of two types:* **Code cells** - contain code to evaluate. Any outputs or results from executing the code are rendered inline after the input code.* **Markdown cells** - contain markdown text that is converted to HTML to produce headers, lists and formatted text (like this content).  SessionsEach opened notebook is associated with a running _session_. If you're familiar with IPython, this is also referred to as a _kernel_. This session is used to execute all the code entered within the notebook, and manages the state (variables you've created, their values, functions and classes you've defined, and any existing python modules you've loaded).You can use the `Reset Session` command on the toolbar above to restart the session and start running code against a clean slate. If your notebook gets disconnected from the session, you can reconnect or recreate it by refreshing the page.  Working in Notebooks  Editing CellsCells can be individually selected, and up/down keys can be used to navigate the notebook. Once you have the appropriate cell selected, you can switch into edit mode either via the `Enter` key or a double click gesture.Once you are done editing the cell, you can toggle markdown cells back into rendered mode and execute code cells to produce results, either using the `Run` button or via the `Shift+Enter` key stroke. This automatically moves selection to the next cell. Use `Ctrl+Enter` to stay on the current cell.**Lets try some of this out.** Following is a markdown cell, and then a code cell with some existing python (and results) ready to be re-run, and an empty code cell for you to try something on your own. [Here is a markdown cell. Go ahead... modify this text.]<jupyter_code>def greet():
    print 'Hello World! Welcome to Notebooks!'
    
greet()<jupyter_output>Hello World! Welcome to Notebooks!<jupyter_text>Editing NotebooksBeyond working within a cell, you can add new cells, delete cells, reorder cells or clear past results to organize your notebook content, or complete your task at hand. These editing capabilities are provided by the toolbar above, as well as via equivalent keystroke shortcuts.Notebooks are automatically saved on a periodic basis. However you can choose to explicitly save the notebook at any point.  CodeA notebook provides an environment to author and execute code. In Cloud Datalab, you will most often write Python code to work with your data. You've already seen a little bit of that above.Cloud Datalab also introduces the ability to author SQL, and JavaScript, or even shell commands. This facility allows you to issue command-like instructions or use alternate languages in the same notebook. These code cells start with an escape sequence,`%%`, that instructs the session to treat the content of the cell as something other than Python. If you're familiar with IPython notebooks, you might have come across the term `cell magic`. Here's an example of a bash cell that lets you invoke a shell command.<jupyter_code>%%bash
ls -al<jupyter_output>total 32
drwxr-x--- 2 223552 5000 4096 Sep 29 22:22 .
drwxr-x--- 7 223552 5000 4096 Sep 29 22:24 ..
-rw-r----- 1 223552 5000 8087 Sep 29 22:22 Introduction to Notebooks.ipynb
-rw-r----- 1 223552 5000 7423 Sep 29 22:22 Introduction to Python.ipynb
-rw-r----- 1 223552 5000 8184 Sep 29 22:22 Working with Cloud Datalab.ipynb
{'fraction_non_alphanumeric': 0.05273485405935737, 'fraction_numerical': 0.026244787834191808, 'mean_word_length': 4.548299319727891, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '613341', 'license': 'Apache-2.0', 'n_tokens_mistral': 1112, 'n_tokens_neox': 973, 'n_words': 625, 'path': 'docs/intro/Introduction to Notebooks.ipynb', 'repo_name': 'yukoga/datalab-archives', 'size': '4077'}