0% found this document useful (0 votes)
50 views

.archivetempMOD01 1-1.1 Intro Python - Ipynb

The document discusses introductory concepts for getting started with Python in Jupyter notebooks. It covers printing 'Hello World', comments, running and saving code cells, and inserting and formatting different cell types. Concepts are explained through text cells and examples are shown in code cells.

Uploaded by

Sekkak Marouane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

.archivetempMOD01 1-1.1 Intro Python - Ipynb

The document discusses introductory concepts for getting started with Python in Jupyter notebooks. It covers printing 'Hello World', comments, running and saving code cells, and inserting and formatting different cell types. Concepts are explained through text cells and examples are shown in code cells.

Uploaded by

Sekkak Marouane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

{

"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 1-1.1 Intro Python\n",
"## Getting started with Python in Jupyter Notebooks\n",
"- **Python 3 in Jupyter notebooks**\n",
"- **`print()`**\n",
"- **comments** \n",
"- data types basics\n",
"- variables\n",
"- addition with Strings and Integers \n",
"- Errors\n",
"- character art \n",
"\n",
"-----\n",
"\n",
"\n",
"><font size=\"5\" color=\"#00A0B2\" face=\"verdana\"> <B>Student will be able
to</B></font>\n",
"- **use Python 3 in Jupyter notebooks** \n",
"- **write working code using `print()` and `#` comments** \n",
"- combine Strings using string addition (`+`)\n",
"- add numbers in code (`+`) \n",
"- troubleshoot errors\n",
"- create character art"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concept</B></font>\n",
"## Hello World! - python&nbsp; `print()` statement\n",
"Using code to write \"Hello World!\" on the screen is the traditional first program when
learning a new language in computer science\n",
"\n",
"Python has a very simple implementation: \n",
"```python\n",
"print(\"Hello World!\")\n",
"``` "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## \"Hello World!\" \n",
"[![view
video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.pn
g)](
http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd2
0e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/6f5
784c6-eece-4dfe-a14e-9dcf6ee81a7f/Unit1_Section1.1-Hello_World.ism/manifest\",\"type\":\"ap
plication/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.win
dows.net/6f5784c6-eece-4dfe-a14e-9dcf6ee81a7f/Unit1_Section1.1-Hello_World.vtt\",\"srclang\"
:\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n",
"\n",
"Our \"Hello World!\" program worked because this notebook hosts a python interpreter that
can run python code cells. \n",
"\n",
"Try showing \n",
"```python \n",
"\"Hello programmer!\" \n",
"``` \n",
"enter new text inside the quotations in the cell above. Click on the cell to edit the code. \n",
"\n",
"What happens if any part of &nbsp;`print`&nbsp; is capitalized or what happens there are no
quotation marks around the greeting?\n",
"## Methods for running the code in a cell\n",
"1. **Click in the cell below** and **press \"Ctrl+Enter\"** to run the code \n",
"&nbsp; &nbsp; or\n",
"2. **Click in the cell below** and **press \"Shift+Enter\"** to run the code and move to the
next cell \n",
"&nbsp;\n",
"3. **Menu: Cell**... \n",
" a. **> Run Cells** runs the highlighted cell(s) \n",
" b. **> Run All Above** runs the highlighted cell and above \n",
" c. **> Run All Below** runs the highlighted cell and below "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font size=\"4\" color=\"#00A0B2\" face=\"verdana\"> <B>Example</B></font>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"# [ ] Review the code, run the code\n",
"print(\"Hello world\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concept</B></font>\n",
"## Comments\n",
"[![view
video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.pn
g)](
http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd2
0e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/34
e2afb1-d07a-44ca-8860-bba1a5476caa/Unit1_Section1.1-Comments.ism/manifest\",\"type\":\"a
pplication/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.wi
ndows.net/34e2afb1-d07a-44ca-8860-bba1a5476caa/Unit1_Section1.1-Comments.vtt\",\"srclan
g\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n",
"When coding, programmers include comments for explanation of how code works for
reminders and to help others who encounter the code\n",
"### comment start with the `#` symbol"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Example</B></font>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# this is how a comment looks in python code\n",
"# every comment line starts with the # symbol"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#B24C00\" face=\"verdana\"> <B>Task 1</B></font>\n",
"## Program: \"Hello World!\" with comment\n",
"- add a comment describing the code purpose\n",
"- create an original \"Hello World\" style message"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n",
"## Notebooks and Libraries\n",
"Jupyter Notebooks provide a balance of jotting down important summary information along
with proving a live code development environment where we can write and run python code.
This course uses cloud hosted Jupyter [Notebooks](https://notebooks.azure.com) on Microsoft
Azure and we will walk through the basics and some best practices for notebook use. \n",
"\n",
"## add a notebook library\n",
"- New: https://notebooks.azure.com/library > New Library\n",
"- Link: from a shared Azure Notebook library link > open link, sign in> clone and Run\n",
"- Add: open library > Add Notebooks > from computer > navigate to file(s)\n",
"\n",
"## working in notebook cells \n",
"- **Markdown cells** display text in a web page format. Markdown is code that formats the
way the cell displays (*this cell is Markdown*) \n",
"&nbsp; \n",
"- **Code cells** contain python code and can be interpreted and run from a cell. Code cells
display code and output. \n",
"&nbsp; \n",
"- **in edit** or **previously run:** cells can display in editing mode or cells can display results
of *code* having been run \n",
" \n",
"[![view
video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.pn
g)](
http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd2
0e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/6b
9134fc-c7d7-4d25-b0a7-bdb79d3e1a5b/Unit1_Section1.1-EditRunSave.ism/manifest\",\"type\":\"
application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.w
indows.net/6b9134fc-c7d7-4d25-b0a7-bdb79d3e1a5b/Unit1_Section1.1-EditRunSave.vtt\",\"srcl
ang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n",
" \n",
"### edit mode \n",
"- **text** cells in editing mode show markdown code \n",
"- Markdown cells keep editing mode appearance until the cell is run \n",
"- **code** (python 3) cells in editing look the same after editing, but may show different run
output \n",
"- clicking another cell moves the green highlight that indicates which cell has active editing
focus \n",
" \n",
"### cells need to be saved\n",
"- the notebook will frequently auto save\n",
"- **best practice** is to manually save after editing a cell using **\"Ctrl + S\"** or alternatively,
**Menu: File > Save and Checkpoint**\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n",
"## Altering Notebook Structure\n",
"[![view
video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.pn
g)](
http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd2
0e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/cb
195105-eee8-4068-9007-64b2392cd9ff/Unit1_Section1.1-Language_Cells.ism/manifest\",\"type\
":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservice
s.windows.net/cb195105-eee8-4068-9007-64b2392cd9ff/Unit1_Section1.1-Language_Cells.vtt\"
,\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n",
"### add a cell\n",
"- Highlight any cell and then... add a new cell using **Menu: Insert > Insert Cell Below** or
**Insert Cell Above**\n",
"- Add with Keyboard Shortcut: **\"ESC + A\"** to insert above or **\"ESC + B\"** to insert
below\n",
"\n",
"### choose cell type\n",
"- Format cells as Markdown or Code via the toolbar dropdown or **Menu: Cell > Cell Type >
Code** or **Markdown** \n",
"- Cells default to Code when created but can be reformatted from code to Markdown and
vice versa \n",
"\n",
"### change notebook page language\n",
"- The course uses Python 3 but Jupyter Notebooks can be in Python 2 or 3 (and a language
called R)\n",
"- To change a notebook to Python 3 go to **\"Menu: Kernel > Change Kernel> Python
3\"**\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &nbsp;\n",
"<font size=\"6\" color=\"#B24C00\" face=\"verdana\"> <B>Task 2</B></font>\n",
"## Insert a new cell\n",
"- Insert a new Code cell below with a comment describing the task\n",
"- edit cell: add print() with the message \"after edit, save!\"\n",
"- run the cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Insert another new cell\n",
"- Insert a new Code cell below \n",
"- edit cell: add print() with the message showing the keyboard Shortcut to save **Ctrl +
s**\n",
"- run the cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Terms of use](http://go.microsoft.com/fwlink/?LinkID=206977) &nbsp; [Privacy &
cookies](https://go.microsoft.com/fwlink/?LinkId=521839) &nbsp; © 2017 Microsoft"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

You might also like