Skip to content

Commit 706ad48

Browse files
committed
Update notebooks for string formatting, single letter variable names
1 parent 0a6d666 commit 706ad48

File tree

5 files changed

+102
-95
lines changed

5 files changed

+102
-95
lines changed

04_jupyter_and_python_intro/python_vars_and_flow_control.ipynb

+24-22
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,11 @@
695695
"metadata": {},
696696
"outputs": [],
697697
"source": [
698-
"my_dict = { 'tuple' : 'An immutable collection of ordered objects',\n",
699-
" 'list' : 'A mutable collection of ordered objects',\n",
700-
" 'dictionary' : 'A mutable collection of objects' }\n",
698+
"my_dict = {\n",
699+
" 'tuple' : 'An immutable collection of ordered objects',\n",
700+
" 'list' : 'A mutable collection of ordered objects',\n",
701+
" 'dictionary' : 'A mutable collection of objects'\n",
702+
"}\n",
701703
"my_dict"
702704
]
703705
},
@@ -1261,8 +1263,8 @@
12611263
"outputs": [],
12621264
"source": [
12631265
"sum = 0\n",
1264-
"for i in range(10):\n",
1265-
" sum += i\n",
1266+
"for index in range(10):\n",
1267+
" sum += index\n",
12661268
"print(sum)"
12671269
]
12681270
},
@@ -1272,7 +1274,7 @@
12721274
"source": [
12731275
"#### For loops can be nested\n",
12741276
"\n",
1275-
"_Note_: for more on formatting strings, see: [https://pyformat.info](https://pyformat.info)"
1277+
"_Note_: for more on formatting strings, see: [https://realpython.com/python-string-formatting/](https://realpython.com/python-string-formatting/)"
12761278
]
12771279
},
12781280
{
@@ -1281,9 +1283,9 @@
12811283
"metadata": {},
12821284
"outputs": [],
12831285
"source": [
1284-
"for i in range(1, 4):\n",
1285-
" for j in range(1, 4):\n",
1286-
" print('%d * %d = %d' % (i, j, i*j)) # Note string formatting here, %d means an integer"
1286+
"for index in range(1, 4):\n",
1287+
" for index2 in range(1, 4):\n",
1288+
" print(f'{index} * {index2} = {index * index2}')"
12871289
]
12881290
},
12891291
{
@@ -1299,10 +1301,10 @@
12991301
"metadata": {},
13001302
"outputs": [],
13011303
"source": [
1302-
"for i in range(10):\n",
1303-
" if i == 4:\n",
1304+
"for index in range(10):\n",
1305+
" if index == 4:\n",
13041306
" break\n",
1305-
"i"
1307+
"index"
13061308
]
13071309
},
13081310
{
@@ -1319,11 +1321,11 @@
13191321
"outputs": [],
13201322
"source": [
13211323
"sum = 0\n",
1322-
"for i in range(10):\n",
1323-
" if (i == 5):\n",
1324+
"for index in range(10):\n",
1325+
" if (index == 5):\n",
13241326
" continue\n",
13251327
" else:\n",
1326-
" sum += i\n",
1328+
" sum += index\n",
13271329
"print(sum)"
13281330
]
13291331
},
@@ -1341,10 +1343,10 @@
13411343
"outputs": [],
13421344
"source": [
13431345
"sum = 0\n",
1344-
"for i in range(10):\n",
1345-
" sum += i\n",
1346+
"for index in range(10):\n",
1347+
" sum += index\n",
13461348
"else:\n",
1347-
" print('final i = %d, and sum = %d' % (i, sum))"
1349+
" print(f'final index = {index}, and sum = {sum}')"
13481350
]
13491351
},
13501352
{
@@ -1361,8 +1363,8 @@
13611363
"outputs": [],
13621364
"source": [
13631365
"my_string = \"SEDS\"\n",
1364-
"for c in my_string:\n",
1365-
" print(c)"
1366+
"for char in my_string:\n",
1367+
" print(char)"
13661368
]
13671369
},
13681370
{
@@ -1559,7 +1561,7 @@
15591561
"outputs": [],
15601562
"source": [
15611563
"def print_name(first, last='the Clown'):\n",
1562-
" print('Your name is %s %s' % (first, last))\n",
1564+
" print(f'Your name is {first} {last}')\n",
15631565
" return"
15641566
]
15651567
},
@@ -1610,7 +1612,7 @@
16101612
"source": [
16111613
"def print_name_age(first, last, age):\n",
16121614
" print_name(first, last)\n",
1613-
" print('Your age is %d' % (age))\n",
1615+
" print(f'Your age is (age)')\n",
16141616
" if age > 55:\n",
16151617
" print('You are really old.')\n",
16161618
" return"

05_pandas_more_git/data_manipulation.ipynb

+7-9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
"import numpy as np"
8686
]
8787
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": []
94+
},
8895
{
8996
"cell_type": "markdown",
9097
"metadata": {},
@@ -1040,15 +1047,6 @@
10401047
"Whenever you do plotting in the IPython notebook, you will want to first run this *magic command* which configures the notebook to work well with plots:"
10411048
]
10421049
},
1043-
{
1044-
"cell_type": "code",
1045-
"execution_count": null,
1046-
"metadata": {},
1047-
"outputs": [],
1048-
"source": [
1049-
"%matplotlib inline"
1050-
]
1051-
},
10521050
{
10531051
"cell_type": "markdown",
10541052
"metadata": {},

0 commit comments

Comments
 (0)