diff --git a/foundations/quickstart.ipynb b/foundations/quickstart.ipynb index 435acd12f..cfd1c28ba 100644 --- a/foundations/quickstart.ipynb +++ b/foundations/quickstart.ipynb @@ -54,6 +54,35 @@ "print(\"Hello interweb\")" ] }, + { + "cell_type": "markdown", + "id": "37e18e9b", + "metadata": {}, + "source": [ + "## Variables in Python" + ] + }, + { + "cell_type": "markdown", + "id": "fc4470b6", + "metadata": {}, + "source": [ + "Variables are the containers for storing data. Variables could be simple and complex. They can represent the primitive data types and point to the other more sophisticated container, e.g. lists, dicts. Later in this notebook you can read the information about these complex types. \n", + "\n", + "As an example you can see a code block with both primitive data value and a complex one" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b61c89f", + "metadata": {}, + "outputs": [], + "source": [ + "primitive_data = 5 # PRIMITIVE DATA VALUE\n", + "complex_data = [3, 4, 5] # COMPLEX DATA VALUE" + ] + }, { "cell_type": "markdown", "id": "4c7a126b", @@ -88,9 +117,9 @@ "source": [ "A few things to note:\n", "\n", - "- Python defaults to counting from 0 (like C) rather than from 1 (like Fortran).\n", - "- Function calls in Python always use parentheses: `print()`\n", - "- The colon `:` denotes the beginning of a definition (here of the repeated code under the `for` loop).\n", + "- As the reader can see from the output, `n` starts from 0 (inclusively) to 3 (exclusively). This indicates that by default iteration starts from 0 (if not otherwise specified)\n", + "- Function calls in Python use parentheses: `print()`\n", + "- The colon `:` denotes the beginning of a new code block (here of the repeated code under the `for` loop).\n", "- Code blocks are identified through indentations.\n", "\n", "To emphasize this last point, here is an example with a two-line repeated block:" @@ -189,7 +218,7 @@ "source": [ "### Integers (`int`)\n", "\n", - "The number `m` above is a good example. We can use the built-in function `type()` to inspect what we've got in memory:" + "The variable `m` above is a good example. We can use the function `type()` to examine the type of variable" ] }, { @@ -303,7 +332,7 @@ "id": "271edb6e", "metadata": {}, "source": [ - "Lists are useful for lots of reasons including iteration:" + "Lists are useful for lots of reasons. As an example, lists could be used for iteration" ] }, { @@ -368,7 +397,7 @@ "id": "87e841a7", "metadata": {}, "source": [ - "remembering that we start counting from zero!" + "Remember that every index in Python starts at 0." ] }, { @@ -397,7 +426,7 @@ "source": [ "### Dictionaries (`dict`)\n", "\n", - "A dictionary is a collection of *labeled objects*. Python uses curly braces `{}` to create dictionaries:" + "A dictionary is a collection of *labeled objects*. While a list is an *ordered* container, the dictionary is an *unordered* one, meaning that the elements in the container do not presume the order. Dictionary elements are accessed via their \"key\" rather than their index. Python uses curly braces `{}` to create dictionaries:" ] }, { @@ -453,159 +482,6 @@ " print(\"The value is:\", mypet[key])" ] }, - { - "cell_type": "markdown", - "id": "fb82a430", - "metadata": {}, - "source": [ - "## Arrays of numbers with NumPy\n", - "\n", - "The vast majority of scientific Python code makes use of *packages* that extend the base language in many useful ways.\n", - "\n", - "Almost all scientific computing requires ordered arrays of numbers, and fast methods for manipulating them. That's what [NumPy](../core/numpy.md) does in the Python world.\n", - "\n", - "Using any package requires an `import` statement, and (optionally) a nickname to be used locally, denoted by the keyword `as`:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "53ba88cf", - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "id": "fb237b33", - "metadata": {}, - "source": [ - "Now all our calls to `numpy` functions will be preceeded by `np.`" - ] - }, - { - "cell_type": "markdown", - "id": "a3391f8d", - "metadata": {}, - "source": [ - "Create a linearly space array of numbers:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ae024132", - "metadata": {}, - "outputs": [], - "source": [ - "# linspace() takes 3 arguments: start, end, total number of points\n", - "numbers = np.linspace(0.0, 1.0, 11)\n", - "numbers" - ] - }, - { - "cell_type": "markdown", - "id": "cc1c2474", - "metadata": {}, - "source": [ - "We've just created a new type of object defined by [NumPy](../core/numpy.md):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c3f3642d", - "metadata": {}, - "outputs": [], - "source": [ - "type(numbers)" - ] - }, - { - "cell_type": "markdown", - "id": "83325c40", - "metadata": {}, - "source": [ - "Do some arithmetic on that array:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "12cc225d", - "metadata": {}, - "outputs": [], - "source": [ - "numbers + 1" - ] - }, - { - "cell_type": "markdown", - "id": "fee4e53c", - "metadata": {}, - "source": [ - "Sum up all the numbers:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3cef5412", - "metadata": {}, - "outputs": [], - "source": [ - "np.sum(numbers)" - ] - }, - { - "cell_type": "markdown", - "id": "ebf2b669", - "metadata": {}, - "source": [ - "## Some basic graphics with Matplotlib\n", - "\n", - "[Matplotlib](../core/matplotlib.md) is the standard package for producing publication-quality graphics, and works hand-in-hand with [NumPy](../core/numpy.md) arrays.\n", - "\n", - "We usually use the `pyplot` submodule for day-to-day plotting commands:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "76f3329e", - "metadata": {}, - "outputs": [], - "source": [ - "import matplotlib.pyplot as plt" - ] - }, - { - "cell_type": "markdown", - "id": "66033cbc", - "metadata": {}, - "source": [ - "Define some data and make a line plot:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "32ca697e", - "metadata": {}, - "outputs": [], - "source": [ - "theta = np.linspace(0.0, 360.0)\n", - "sintheta = np.sin(np.deg2rad(theta))\n", - "\n", - "plt.plot(theta, sintheta, label='y = sin(x)', color='purple')\n", - "plt.grid()\n", - "plt.legend()\n", - "plt.xlabel('Degrees')\n", - "plt.title('Our first Pythonic plot', fontsize=14)" - ] - }, { "cell_type": "markdown", "id": "04615882",