{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "######Run the cell below to load the visual style of this notebook." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.core.display import HTML\n", "css_file = 'styles.css'\n", "HTML(open(css_file, \"r\").read())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Exercise

\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Draw diagrams showing what variables refer to what values after each statement in the following program:\n", "\n", "```python\n", "import numpy as np\n", "mass = 58.5\n", "age = 36\n", "```\n", "-----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Learning Objectives

\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Explain what a library is, and what libraries are used for.\n", "- Load a Python library and use the things it contains.\n", "- Read tabular data from a file into a program.\n", "- Assign values to variables.\n", "- Select individual values and subsections from data.\n", "- Perform operations on arrays of data.\n", "- Display simple graphs.\n", "-------" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Data which can be modified in place is called *mutable*, while data which cannot be modified is called *immutable*. Strings and numbers are immutable. This does not mean that variables with string or number values are constants, but when we want to change the value of a string or number variable, we can only replace the old value with a completely new value.\n", "\n", "Lists and arrays, on the other hand, are mutable: we can modify them after they have been created. We can change individual elements, append new elements, or reorder the whole list. For some operations, like sorting, we can choose whether to use a function that modifies the data in place or a function that returns a modified copy and leaves the original unchanged.\n", "\n", "Be careful when modifying data in place. If two variables refer to the same list, and you modify the list value, it will change for both variables! If you want variables with mutable values to be independent, you must make a copy of the value when you assign it.\n", "\n", "Because of pitfalls like this, code which modifies data in place can be more difficult to understand. However, it is often far more efficient to modify a large data structure in place than to create a modified copy for every small change. You should consider both of these aspects when writing your code.\n", "\n", "----" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "panel": { "hint": true, "lo": false, "task": false, "title": "Another hint" } }, "source": [ "This markdown cell is styled using the \"Style cells\" notebook extension" ] } ], "metadata": { "kernelspec": { "display_name": "IPython (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.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }