{ "cells": [ { "cell_type": "markdown", "id": "b8c2a09f-6a32-4fc1-ae61-086ef4cff2ef", "metadata": {}, "source": [ "# Jupyter notebook basics\n", "\n", "This notebook demonstrates how to use Jupyter notebooks:\n", "\n", "- Cell types (markdown vs code)\n", "- Running code\n", "- Execution order\n", "- Kernel behavior" ] }, { "cell_type": "code", "execution_count": 1, "id": "5ad2f245-fc0a-4ba1-8a8b-802d7d515903", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This notebook is connected to a Python 3.10 kernel\n" ] } ], "source": [ "print('This notebook is connected to a Python 3.10 kernel')" ] }, { "cell_type": "markdown", "id": "b28df720-159c-4e23-a2b1-54e450111081", "metadata": {}, "source": [ "## Execution order" ] }, { "cell_type": "code", "execution_count": 2, "id": "148a4d95-646b-4395-9933-05048fea27a8", "metadata": {}, "outputs": [], "source": [ "user_name = 'George'" ] }, { "cell_type": "code", "execution_count": 3, "id": "e1663f35-3502-4cd4-b074-135ace3209fd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "George\n" ] } ], "source": [ "print(user_name)" ] }, { "cell_type": "code", "execution_count": 4, "id": "a0a3b842-83bb-4705-a402-2d57c447cae7", "metadata": {}, "outputs": [], "source": [ "user_name = 'Laura'" ] }, { "cell_type": "code", "execution_count": 5, "id": "9d4a0aea-d62f-4f8a-9445-7286f1f51108", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Laura\n" ] } ], "source": [ "print(user_name)" ] }, { "cell_type": "markdown", "id": "b8359c22-2b1b-4b8b-84cb-1ef73ba4a972", "metadata": {}, "source": [ "## Errors" ] }, { "cell_type": "code", "execution_count": 6, "id": "73daca90-7fc4-4fdb-9011-1fa24c86a8e7", "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "'(' was never closed (4255644718.py, line 1)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"/tmp/ipykernel_307/4255644718.py\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m print('This is a syntax error'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m '(' was never closed\n" ] } ], "source": [ "print('This is a syntax error'" ] }, { "cell_type": "code", "execution_count": 8, "id": "83a2c682-f81a-4ffe-93c0-8cd3570989b8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The next line is a runtime error\n" ] }, { "ename": "NameError", "evalue": "name 'undefined_var' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/tmp/ipykernel_307/2790303741.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'The next line is a runtime error'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mundefined_var\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'undefined_var' is not defined" ] } ], "source": [ "print('The next line is a runtime error')\n", "print(undefined_var)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 [3.10]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.2" } }, "nbformat": 4, "nbformat_minor": 5 }