|
442 | 442 | "cell_type": "markdown", |
443 | 443 | "metadata": {}, |
444 | 444 | "source": [ |
445 | | - "The [Python Tutorial](http://docs.python.org/2/tutorial/introduction.html#using-python-as-a-calculator) has more on using Python as an interactive shell. The [IPython tutorial](http://ipython.org/ipython-doc/dev/interactive/tutorial.html) makes a nice complement to this, since IPython has a much more sophisticated iteractive shell." |
| 445 | + "The [Python Tutorial](http://docs.python.org/2/tutorial/introduction.html#using-python-as-a-calculator) has more on using Python as an interactive shell. The IPython [documentation](http://ipython.readthedocs.io/en/stable/) makes a nice complement to this, since IPython has a much more sophisticated iteractive shell. In particular, have a look at the \"Using IPython for interactive work\" section of the website." |
446 | 446 | ] |
447 | 447 | }, |
448 | 448 | { |
|
1024 | 1024 | "metadata": {}, |
1025 | 1025 | "source": [ |
1026 | 1026 | "## Iteration, Indentation, and Blocks\n", |
1027 | | - "One of the most useful things you can do with lists is to *iterate* through them, i.e. to go through each element one at a time. To do this in Python, we use the **for** statement:" |
| 1027 | + "One of the most useful things you can do with lists is to *iterate* through them, i.e. to go through each element one at a time. To do this in Python, we use the `for` statement:" |
1028 | 1028 | ] |
1029 | 1029 | }, |
1030 | 1030 | { |
|
1057 | 1057 | "cell_type": "markdown", |
1058 | 1058 | "metadata": {}, |
1059 | 1059 | "source": [ |
1060 | | - "This code snippet goes through each element of the list called **days_of_the_week** and assigns it to the variable **day**. It then executes everything in the indented block (in this case only one line of code, the print statement) using those variable assignments. When the program has gone through every element of the list, it exists the block.\n", |
| 1060 | + "This code snippet goes through each element of the list called **days_of_the_week** and assigns it to the variable **day**. It then executes everything in the indented block (in this case only one line of code, the `print` statement) using those variable assignments. When the program has gone through every element of the list, it exits the block.\n", |
1061 | 1061 | "\n", |
1062 | 1062 | "(Almost) every programming language defines blocks of code in some way. In Fortran, one uses END statements (ENDDO, ENDIF, etc.) to define code blocks. In C, C++, and Perl, one uses curly braces {} to define these blocks.\n", |
1063 | 1063 | "\n", |
|
1095 | 1095 | "cell_type": "markdown", |
1096 | 1096 | "metadata": {}, |
1097 | 1097 | "source": [ |
1098 | | - "The **range()** command is particularly useful with the **for** statement to execute loops of a specified length:" |
| 1098 | + "The `range()` command is particularly useful with the `for` statement to execute loops of a specified length:" |
1099 | 1099 | ] |
1100 | 1100 | }, |
1101 | 1101 | { |
|
1134 | 1134 | ], |
1135 | 1135 | "source": [ |
1136 | 1136 | "for i in range(20):\n", |
1137 | | - " print \"The square of \",i,\" is \",i*i" |
| 1137 | + " print \"The square of \",i,\" is \",i**2" |
1138 | 1138 | ] |
1139 | 1139 | }, |
1140 | 1140 | { |
|
1324 | 1324 | }, |
1325 | 1325 | { |
1326 | 1326 | "cell_type": "code", |
1327 | | - "execution_count": 41, |
| 1327 | + "execution_count": 1, |
1328 | 1328 | "metadata": { |
1329 | 1329 | "collapsed": false |
1330 | 1330 | }, |
|
1333 | 1333 | "name": "stdout", |
1334 | 1334 | "output_type": "stream", |
1335 | 1335 | "text": [ |
1336 | | - "Sun\n" |
| 1336 | + "Wed\n" |
1337 | 1337 | ] |
1338 | 1338 | } |
1339 | 1339 | ], |
1340 | 1340 | "source": [ |
1341 | | - "day = \"Sunday\"\n", |
| 1341 | + "day = \"Wednesday\"\n", |
1342 | 1342 | "abbreviation = day[:3]\n", |
1343 | 1343 | "print abbreviation" |
1344 | 1344 | ] |
|
1400 | 1400 | }, |
1401 | 1401 | { |
1402 | 1402 | "cell_type": "code", |
1403 | | - "execution_count": 43, |
| 1403 | + "execution_count": 2, |
1404 | 1404 | "metadata": { |
1405 | 1405 | "collapsed": false |
1406 | 1406 | }, |
|
1409 | 1409 | "name": "stdout", |
1410 | 1410 | "output_type": "stream", |
1411 | 1411 | "text": [ |
1412 | | - "Sleep in\n" |
| 1412 | + "Go to work\n" |
1413 | 1413 | ] |
1414 | 1414 | } |
1415 | 1415 | ], |
|
1431 | 1431 | }, |
1432 | 1432 | { |
1433 | 1433 | "cell_type": "code", |
1434 | | - "execution_count": 44, |
| 1434 | + "execution_count": 3, |
1435 | 1435 | "metadata": { |
1436 | 1436 | "collapsed": false |
1437 | 1437 | }, |
1438 | 1438 | "outputs": [ |
1439 | 1439 | { |
1440 | 1440 | "data": { |
1441 | 1441 | "text/plain": [ |
1442 | | - "True" |
| 1442 | + "False" |
1443 | 1443 | ] |
1444 | 1444 | }, |
1445 | | - "execution_count": 44, |
| 1445 | + "execution_count": 3, |
1446 | 1446 | "metadata": {}, |
1447 | 1447 | "output_type": "execute_result" |
1448 | 1448 | } |
|
0 commit comments