{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prerequisites \n",
    "\n",
    "None\n",
    "\n",
    "# Types\n",
    "\n",
    "Python essentially can be thought of as having three types of single object variable:\n",
    "\n",
    "- **Strings** - a textual variable, such as a word or a sentance \n",
    "- **Numbers** - some numerical information \n",
    "- **Boolean** - Boolean variables can be either `True` or `False`, this is an important component of logic\n",
    "\n",
    "The particular *type* of variable defines the specific operations that may be performed on them. \n",
    "The *type* of any variable may be determined with the `type()` function (which is intrinsic to Python). \n",
    "\n",
    "<hr>\n",
    "\n",
    "## Strings\n",
    "\n",
    "*Strings* (often abbrevated to `str`) are variables which are **textual** in nature. \n",
    "When assigning a string, the text should be placed between either inverted commas (`'Like This'`) or quotation marks (`\"Like This\"`). \n",
    "This informs the Python interperator that the variable is of type `str`. \n",
    "For example, if we want to assign the string `'Hello World'` to the variable `greeting`, the following code is used,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "greeting = 'Hello World'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Printing this `greeting` (using the `print()` function) allows you to run the [archetypical first programming exercise](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "print(greeting)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This exercise is often the first thing that is taught when learning a new programming language, so we feel that it is important, in this introductory text, that we show it. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(greeting)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that as mentioned above, either inverted commas or quotation marks may be used so,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "greeting2 = \"Hello World\"\n",
    "print(greeting2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "is equivalent to,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "greeting = 'Hello World'\n",
    "print(greeting)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "While strings are textual in nature, they may still contain numerical information. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The atomic number (Z) of Hydrogen is 1. \n",
      "\n"
     ]
    }
   ],
   "source": [
    "hydrogen_atomic = \"The atomic number (Z) of Hydrogen is 1. \\n\"\n",
    "print(hydrogen_atomic)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the above example, the number 1 is a component of the string `hydrogen` and the `\\n` means that a new line should be taken.\n",
    "This means that the Python interperator does not recognise it has a number so cannot perform mathematical operations (discussed below) on it.\n",
    "\n",
    "#### Exercise\n",
    "\n",
    "In the cell below, define a variable string containing your favourite chemical element (this is a chemistry textbook after all), and have the Python interpreter print it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Operations\n",
    "\n",
    "The textual nature of a string means that is it not possible (nor does it really make sense to) perform mathematical operations on them. \n",
    "However, there are some operations that can be performed on a string, that initially, may appear mathematical in nature. \n",
    "For examples, it is possible to \"add\" strings together,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The atomic number (Z) of Hydrogen is 1. \n",
      "The mass number (A) of Hydrogen is 1. \n"
     ]
    }
   ],
   "source": [
    "hydrogen_mass = \"The mass number (A) of Hydrogen is 1. \"\n",
    "print(hydrogen_atomic + hydrogen_mass)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, the addition symbol (`+`) is used to *concatenate* the two strings, where the latter is appended to the end of the former. \n",
    "In mathematics, multiplication is analogous to multiple addition of a number, \n",
    "$$\n",
    "5 \\times 3 = 5 + 5 + 5 = 15.\n",
    "$$\n",
    "This analogy may be applied to the use of the multiplication symbol (in Python, `*`) as an operator on a string. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The atomic number (Z) of Hydrogen is 1. \n",
      "The atomic number (Z) of Hydrogen is 1. \n",
      "The atomic number (Z) of Hydrogen is 1. \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(hydrogen_atomic * 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Where, by \"multiplying\" the string by 3, we are concatenating three instances of the `hydrogen_atomic` variable. \n",
    "\n",
    "If you attempt to subtract one string from another though, you will be met with an error message. \n",
    "*Reading from the bottom*, this error tells us that we have a `TypeError: unsupported operand type(s) for -: 'str' and 'str'` (more about errors and error messages can be found in Chapter X). \n",
    "This message says that it is not possible to subtract one string from another, this is because the `-` operator has no alternate meaning (like `+` means to concatenate) for strings."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for -: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-9-281ed67a144c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhydrogen_atomic\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mhydrogen_mass\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "print(hydrogen_atomic - hydrogen_mass)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The same is the case for operating on a string with any of the other standard operators (division, floor division, and power) in Python. \n",
    "\n",
    "#### Exercise \n",
    "\n",
    "Test the other standard operations on a pair of strings in the cell below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>\n",
    "\n",
    "## Numbers\n",
    "\n",
    "*Numbers* are a broad definition of a type in Python, indeed within numbers there are three other, more specific, data sub-types. \n",
    "Loosely, numbers are any numerical data in Python, and variable of this broad type are defined as follows,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17\n"
     ]
    }
   ],
   "source": [
    "chlorine_z = 17\n",
    "print(chlorine_z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "273.16\n"
     ]
    }
   ],
   "source": [
    "triple_point_h2o = 273.16\n",
    "print(triple_point_h2o)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Shown above are two of the three possible numerical types in Python. \n",
    "The first is the type `int`, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(chlorine_z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is a *whole number*, a number without a decimal point (also known as an integer). \n",
    "The example shown above is the atomic number of chlorine, which is a whole number of 17 (a chlorine atom contains exactly 17 protons, any more or any less and it would be a different atom and it is not possible to have a 17.2 protons!). \n",
    "While the second example is of the type `float`,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(triple_point_h2o)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is a *floating point* number, a number with a decimal point. \n",
    "The given example is that of the triple point of water in units of Kelvin, which is not 273 K or 274 K, but rather lies somewhere in between on the number line. \n",
    "\n",
    "<center>\n",
    "    <img src=\"../images/number_line.png\" width=50%>\n",
    "    <br>\n",
    "    <i>\n",
    "        Figure 1. The position of 273.16 on the number line.\n",
    "    </i>\n",
    "</center>\n",
    "\n",
    "### Floating point precision\n",
    "\n",
    "Due to the way that the computer stores floating point numbers, you may notice some unusual results. \n",
    "For example (this may vary from computer to computer),"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.30000000000000004\n"
     ]
    }
   ],
   "source": [
    "print(0.1 + 0.2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When run on my computer the above code returns `0.30000000000000004`, which we know is not correct. \n",
    "This is due to the *base 2* (ones and zeros, also known as binary) way that computers store information and the inability to represent `0.1` exactly in base 2.\n",
    "We make the assumption through this book, and generally, that the precision that the data is stored to is sufficient for our use cases. \n",
    "However, this may not always be the case so it is important to be aware of it!\n",
    "\n",
    "Another way that floating point numbers may be represented, which can be useful in the physical sciences, is with *scientific notation* (also known as standard form). \n",
    "Python understands scientific notation as follow, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "avogardo_constant = 6.022e23"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "where the coefficient of the standard notation value preceeds the `e` and the exponent follows. \n",
    "For example, you may be used to seeing Avogardo's constant written as, \n",
    "\n",
    "$$ N_a = 6.022\\times 10 ^{23}. $$\n",
    "\n",
    "This way of defining a number will always produce a `float` type number, regardless of whether the decimal point is included or not."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(avogardo_constant)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(3e8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Opertions\n",
    "\n",
    "Python has five standard mathematical opertions that my be performed between variables of numerical data. \n",
    "\n",
    "<center>\n",
    "    <i>\n",
    "        Table 1. The five standard mathematical operations that may be performed on numerical data.\n",
    "    </i>\n",
    "</center>\n",
    "\n",
    "| Operation     | Mathematical Notation | Pythonic Notation |\n",
    "|---------------|-----------------------|-------------------|\n",
    "| Addition      | $a + b$               | `a + b`           |\n",
    "| Subtraction   | $a - b$               | `a - b`           |\n",
    "| Multiplicaton | $a \\times b$          | `a * b`           |\n",
    "| Division      | $a \\div b$               | `a / b`           |\n",
    "| Exponent      | $a ^ b$               | `a ** b`          |\n",
    "\n",
    "Each of these operations act exactly as you would expect. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.0\n"
     ]
    }
   ],
   "source": [
    "print(3. + 2.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0\n"
     ]
    }
   ],
   "source": [
    "print(3. - 2.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.0\n"
     ]
    }
   ],
   "source": [
    "print(3. * 2.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.5\n"
     ]
    }
   ],
   "source": [
    "print(3. / 2.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9.0\n"
     ]
    }
   ],
   "source": [
    "print(3. ** 2.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You may have noticed that in the five lines of code above, numbers of type `float` were used for all of them and the numbers that were returned were also of type `float`.\n",
    "These operations can also be used with numbers of type `int`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "print(3 + 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print(3 - 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print(3 * 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.5\n"
     ]
    }
   ],
   "source": [
    "print(3 / 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "print(3 ** 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice that all of the numbers that are returned are of type `int`, except for the result of `3 / 2`, which the Python interperator has *intelligently* returned as a `float` (as the `int` `1` or `2` would not be correct). \n",
    "This is achieved by the division operator automatically *upscaling* all of its *operands* (the numbers that it operates on) to type `float` before the division is performed.\n",
    "\n",
    "It was shown above that a number can be assigned to a variable, additionally this variable can then be used in a mathematical opertation. \n",
    "Consider converting from kilojoules to calories, where you divide by $4.184$. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "kj = 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "calorie = 100 / 4.184"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23.900573613766728\n"
     ]
    }
   ],
   "source": [
    "print(calorie)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Above, we have reused the `kj` variable in the creation of a new variable `calorie` and printed this. \n",
    "\n",
    "#### Exercise \n",
    "\n",
    "Investigate, in the cell below, the effect of changing the value of `kj` **after** the variable `calorie` is defined. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Order of operations\n",
    "\n",
    "A single line of Python can contain many different mathematical operations, therefore it is important that Python has an order in which these operations should be performed. \n",
    "This is the standard mathematical order of operations, this is known as many things (PIMDAS, POMDAS, BIDMAS, etc.). \n",
    "However, we will refer to this as BODMAS:\n",
    "\n",
    "- **B**rackets\n",
    "- **O**rder\n",
    "- **D**ivision\n",
    "- **M**ultiplication\n",
    "- **A**ddition\n",
    "- **S**ubtraction\n",
    "\n",
    "#### Exercise\n",
    "\n",
    "Write the following equations in the cells below, before you returns them use a calculator and BODMAS to determine what the answer should be. \n",
    "\n",
    "- $3 \\div (4 + 2) \\times 3$\n",
    "- $8 + 9 \\times 7 ^ 3$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Complex numbers\n",
    "\n",
    "Many chemistry students (and chemistry educators!) ignore the importance of complex numbers in the chemical sciences. \n",
    "However, there are many aspects where complex numbers are relavent, such as the amount by which an X-ray is scattered by an atom and the evalution of the wavefunction in quantum mechanics. \n",
    "Therefore, it is important that we (briefly) discuss complex numbers and how to use them in Python. \n",
    "\n",
    "Typically, we would expect a complex number to be written as $3 + 1i$, where the number has a real component of 3 and a complex component of 1. \n",
    "In Python, a `j` is used instead of an $i$, this is due to Python following a convention in electrical engineering where the complex component is denoted with a $j$. \n",
    "Therefore, to write the complex number mentioned earlier ($3 + 1i$) would be the following, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3+1j)\n"
     ]
    }
   ],
   "source": [
    "print(3 + 1j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(3 + 1j)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Mixed type operations and type hierarchy\n",
    "\n",
    "The upscaling of types does not only happen for the division operator, it will also occur when two objects of different types are operated on. \n",
    "For example, consider what would happen if an `int` is added to a `float`, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.5\n"
     ]
    }
   ],
   "source": [
    "print(1.5 + 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1.5 + 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result is a float, this is because the `int` is upscaled to be a `float` before the addition is performed. \n",
    "Essentially what the computer sees is, \n",
    "```\n",
    ">>> 1.5 + 2      # float plus int\n",
    ">>> 1.5 + 2.0    # Upscale int to float\n",
    ">>> 3.5          # Do addition\n",
    "```\n",
    "This is the case for any mathematical operation between a float and an int. \n",
    "\n",
    "In order for the upscaling to make sense, a *hierarchy of types* must be defined.\n",
    "In Python for numerical variables this is as follows:\n",
    "1. `complex`\n",
    "2. `float`\n",
    "3. `int`\n",
    "\n",
    "So an `int` will upscale to a `float` and a `float` to a `complex`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>\n",
    "\n",
    "## Boolean\n",
    "\n",
    "The final type in Python that we will discuss in this section is the Boolean, named for George Boole who defined an early algebraic system of logic in the 19th century (which is fundamental to modern computer science). \n",
    "The Boolean or `bool` type is a logical variable type, meaning that it is associated with computational logic.\n",
    "A `bool` can take one of two values, either `True` or `False`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that in Python, it is important that these are write **exactly** as shown above (in title case), or an error will be thrown."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'true' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-37-d6f700e50a15>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'true' is not defined"
     ]
    }
   ],
   "source": [
    "print(true)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Logical operators\n",
    "\n",
    "The utility of `bool` types is due to their application in logic, where it is possible to determine if a particular statement is `True` or `False`.\n",
    "For example, the `==` operator determines if the item on the left *is equal to* that on the right. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 + 2 == 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 + 1 == -4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Of course, `==` is not the only logical operator. \n",
    "\n",
    "<center>\n",
    "    <i>\n",
    "        Table 2. The six standard logical operations that may be performed.\n",
    "    </i>\n",
    "</center>\n",
    "\n",
    "| Operation                | Mathematical Notation | Pythonic Notation |\n",
    "|--------------------------|-----------------------|-------------------|\n",
    "| Is Equal To              | $=$                   | `==`              |\n",
    "| Less Than                | $<$                   | `<`               |\n",
    "| Less Than or Equal to    | $\\leq$                | `<=`              |\n",
    "| Greater Than             | $>$                   | `>`               |\n",
    "| Greater Than or Equal to | $\\geq$                | `>=`              |\n",
    "| Is Not Equal to          | $\\neq$                | `!=`              |\n",
    "\n",
    "Each of these operators has the same effect as their mathematical equivalent when applied to numerical data. \n",
    "However, some of these operators are not limited to numerical data. \n",
    "For example, the `==` and `!=` may be used for any data type,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Hello World' != 'HELLO WORLD'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The .upper() class-function will make the string uppercase\n",
    "'Hello World'.upper() == 'HELLO WORLD'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise \n",
    "\n",
    "Using the cells below, find the result of the following logical operations:\n",
    "\n",
    "- $1 = 4$\n",
    "- $10 < 15$ \n",
    "- $3.1415 \\neq 3$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Placeholder"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
