Skip to content

Commit b5654d0

Browse files
committed
update
1 parent 870e57a commit b5654d0

1 file changed

Lines changed: 80 additions & 38 deletions

File tree

python_tutorial.ipynb

Lines changed: 80 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
"Python has a number of types. You need to be familiar with some of them as a start, then you will learn about more as you go. Let's quickly investigate some of these here:"
1717
]
1818
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"#Integers and floats"
24+
]
25+
},
1926
{
2027
"cell_type": "code",
2128
"execution_count": 5,
@@ -81,13 +88,13 @@
8188
]
8289
},
8390
{
84-
"cell_type": "code",
85-
"execution_count": null,
91+
"cell_type": "markdown",
8692
"metadata": {
8793
"collapsed": true
8894
},
89-
"outputs": [],
90-
"source": []
95+
"source": [
96+
"# Strings"
97+
]
9198
},
9299
{
93100
"cell_type": "code",
@@ -112,15 +119,6 @@
112119
"print \"Hello world\""
113120
]
114121
},
115-
{
116-
"cell_type": "code",
117-
"execution_count": null,
118-
"metadata": {
119-
"collapsed": true
120-
},
121-
"outputs": [],
122-
"source": []
123-
},
124122
{
125123
"cell_type": "code",
126124
"execution_count": 2,
@@ -174,6 +172,13 @@
174172
"print \"The type of the value: \", len(feeling)\n"
175173
]
176174
},
175+
{
176+
"cell_type": "markdown",
177+
"metadata": {},
178+
"source": [
179+
"# Lists"
180+
]
181+
},
177182
{
178183
"cell_type": "code",
179184
"execution_count": 7,
@@ -320,49 +325,86 @@
320325
]
321326
},
322327
{
323-
"cell_type": "code",
324-
"execution_count": null,
325-
"metadata": {
326-
"collapsed": true
327-
},
328-
"outputs": [],
329-
"source": []
330-
},
331-
{
332-
"cell_type": "code",
333-
"execution_count": null,
328+
"cell_type": "markdown",
334329
"metadata": {
335330
"collapsed": true
336331
},
337-
"outputs": [],
338-
"source": []
332+
"source": [
333+
"# Dictionaries"
334+
]
339335
},
340336
{
341337
"cell_type": "code",
342-
"execution_count": null,
338+
"execution_count": 3,
343339
"metadata": {
344-
"collapsed": true
340+
"collapsed": false
345341
},
346-
"outputs": [],
347-
"source": []
342+
"outputs": [
343+
{
344+
"name": "stdout",
345+
"output_type": "stream",
346+
"text": [
347+
"{777: 'Mary', 1111: 'John'}\n",
348+
"2\n",
349+
"Mary\n"
350+
]
351+
}
352+
],
353+
"source": [
354+
"# A Ptthon dictionary is a \"mapping\" type. We map a \"key\" to a \"value\".\n",
355+
"# For example, we can map a \"student_id\" to the \"name\" of a student.\n",
356+
"# The sytax is simple: We use the curly braces, and delimit each key:value pair by the \"colon\"\n",
357+
"students={1111: \"John\", 777: \"Mary\"}\n",
358+
"print \"Printing the 'students' dict: \", students\n",
359+
"print \"The length of the 'students' dict is: \", len(students)\n",
360+
"# This is how you access the value of the key 777\n",
361+
"print print \"The value of the key 777 in the 'students' dict is: \", students[777]"
362+
]
348363
},
349364
{
350365
"cell_type": "code",
351-
"execution_count": null,
366+
"execution_count": 5,
352367
"metadata": {
353-
"collapsed": true
368+
"collapsed": false
354369
},
355-
"outputs": [],
356-
"source": []
370+
"outputs": [
371+
{
372+
"name": "stdout",
373+
"output_type": "stream",
374+
"text": [
375+
"The value of the key 'CS' in the 'students' dict is: John\n"
376+
]
377+
}
378+
],
379+
"source": [
380+
"# The keys don't have to be integers; they can be strings too. \n",
381+
"# Lets have keys represent the school of a student:\n",
382+
"students={\"CS\": \"John\", \"Business\": \"Mary\"}\n",
383+
"print \"The value of the key 'CS' in the 'students' dict is: \", students['CS']"
384+
]
357385
},
358386
{
359387
"cell_type": "code",
360-
"execution_count": null,
388+
"execution_count": 6,
361389
"metadata": {
362-
"collapsed": true
390+
"collapsed": false
363391
},
364-
"outputs": [],
365-
"source": []
392+
"outputs": [
393+
{
394+
"name": "stdout",
395+
"output_type": "stream",
396+
"text": [
397+
"The value of the key 'CS' in the 'students' dict is: ['John', 'Alex', 'Amanda']\n"
398+
]
399+
}
400+
],
401+
"source": [
402+
"# A value in a Python dict can be a string, a list, another dict, etc.\n",
403+
"# So, if \"Alex\" and \"Amanda\" are also students in CS, then we can have the value for the key 'CS' as a list:\n",
404+
"students={\"CS\": [\"John\", \"Alex\", \"Amanda\"] , \"Business\": \"Mary\"}\n",
405+
"# And now when we print, we get all the students in CS as a full list:\n",
406+
"print \"The value of the key 'CS' in the 'students' dict is: \", students['CS']"
407+
]
366408
},
367409
{
368410
"cell_type": "code",

0 commit comments

Comments
 (0)