{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ea33aa07-6882-42c8-9087-6bdf4b3cc4f3",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Objects and variables"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5d3cb3e-8fc2-45fc-9339-c7cbdc075512",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Objects can be stored in variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "961625c0-c89a-46d2-9499-85cb88e247f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"John\" \n",
    "last_name = \"Smith\"\n",
    "id = \"10221\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "fba19609-dd11-4d52-89a8-056afc864ee7",
   "metadata": {},
   "outputs": [],
   "source": [
    "members = 5 \n",
    "height = 1.75"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7ff1d21-c0fa-4761-821a-df8916973324",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Objects can also be produced by functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4cc64548-9a9d-4edd-a8f4-22d4e6a043c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "What is your name? Ardit\n"
     ]
    }
   ],
   "source": [
    "name = input(\"What is your age?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "42187a85-7484-45d4-8f77-754d703da44f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Ardit'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "130c3fa6-ba50-45a2-8dd2-33e5ff4f8c60",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "What is your height? 175\n"
     ]
    }
   ],
   "source": [
    "name = input(\"What is your height?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "df9322ce-596b-4b1b-b0a2-8c69664ca9f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'175'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ed05713-2533-4038-85e4-ccf37597a146",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Converting to another type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "33d7bcd6-df5b-4ffd-9389-5fc78d35a44d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "What is your height? 175\n"
     ]
    }
   ],
   "source": [
    "name = float(input(\"What is your height?\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7803a0b0-66e1-4d6a-b20e-292b78aa6cba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "175.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37aa48af-7b88-481f-afe2-c9e0efa73dca",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Functions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93672bea-be8b-4dc4-aa86-fa8fbf37cd09",
   "metadata": {},
   "source": [
    "#### Not all functions return a value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e25c9014-2a00-48ff-9eda-6fae37fb4a3f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello\n"
     ]
    }
   ],
   "source": [
    "x = print(\"Hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "71737696-b1af-4589-bdb6-5d1047d65a73",
   "metadata": {},
   "outputs": [],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "993a97ff-77a0-4d3c-b843-a4f1714461c6",
   "metadata": {},
   "source": [
    "#### Custom functions can also return or not a value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7b1f8d64-a034-441d-bd2d-fa769a55f1bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo():\n",
    "    value = 10\n",
    "    return value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9c39f6aa-4294-4f37-86ec-0d1c2fc2e3a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = foo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "417d2423-5a2e-4f42-9130-3447b8299fdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "8a7ace39-da91-4d8f-8389-45d3a66a3b65",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo():\n",
    "    value = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "256590a8-aeb5-4bcb-a46d-28522b6d16a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = foo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5d9a7c15-91d1-4ee2-8280-5324918f119d",
   "metadata": {},
   "outputs": [],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2450fa5-4f2d-46d7-ba97-14f310822034",
   "metadata": {},
   "source": [
    "#### Return vs Print"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "78743b34-dfcb-40e6-9d24-4a2e74024cf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo1():\n",
    "    value = 10\n",
    "    return value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "8ee7c240-0bb0-4893-98da-45d628fa2940",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo2():\n",
    "    value = 10\n",
    "    print(value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "a9dd400d-1dcf-45a4-8394-2e460abf0144",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1 = foo1()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "bb9c168a-3f06-41d7-9131-db2b2778edd6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "21df03b8-0e97-4115-99a0-ba62f62cf827",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "x2 = foo2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d3b74dd7-fcc9-4222-ac9e-5930dbb74bfe",
   "metadata": {},
   "outputs": [],
   "source": [
    "x2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17ea0d22-dd7d-498c-95e1-c3dec6a43af7",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true,
    "tags": []
   },
   "source": [
    "#### Functions with parameters/arguments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "16f2b69b-0b32-48e4-85b7-8ce1264d3b84",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo(number):\n",
    "    result = number * number\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "dcdc5c59-9b88-4310-b9b7-22feb5c72f7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# With argument name\n",
    "x = foo(number=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2f4e0ef4-56ab-4cc7-b5a2-58b7b9a3ab10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "45bbbc51-0a2d-4ca5-af72-aaff6d312640",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Without argument name\n",
    "x = foo(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b6f015a-7aac-4f34-bcf2-e681019491bc",
   "metadata": {},
   "source": [
    "#### Functions with multiple parameters/arguments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "dddf15e1-1d51-4a6e-8ad1-e02fe636f602",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo(number1, number2):\n",
    "    result = number1 * number2\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "e3d02110-2d67-4397-985d-229f1cc04d8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = foo(10, 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "1a7efc2e-3b26-481b-9be5-5309a07da68d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83c42e19-4202-4258-8efe-8e3b9f278b22",
   "metadata": {},
   "source": [
    "#### Functions with default parameters/arguments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "34290963-14a1-44b8-b745-c09e6916cb63",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo(number1, number2=2):\n",
    "    result = number1 * number2\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "798370d6-e7f6-4130-97d4-add1f5303b96",
   "metadata": {},
   "outputs": [],
   "source": [
    "# The default argiment can be ommited\n",
    "x = foo(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "7f9ec230-ec20-4ef2-971b-c462a4df19b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "3da4d637-f698-416f-b50c-f727a86829d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = foo(10, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "3d3cda25-09b3-417c-93e1-674162302ea6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b72a505-ed5a-435b-ba73-a12d489f7d0a",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "9469d38f-0486-4815-a5d9-ac0020af0fed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'HELLO THERE'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"hello there\".upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "acf49c26-efcb-47e8-805a-dbb883bd1f8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello there'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"hello there\".capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "b9ef637d-ed06-42c3-b834-ee60e60a2635",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello There'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"hello there\".title()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "39acd0a8-b6e7-48e6-96c2-9e3e1d2bbe61",
   "metadata": {},
   "outputs": [],
   "source": [
    "greeting = \"hello there\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "84824cd0-6341-4f97-8cbf-0739adb6d3ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello There'"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "greeting_new = greeting.title()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e37f8314-c1e1-4c35-9e20-5411ce88de57",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Methods that return an output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "123f9998-aae1-49a0-acb3-c91e3ea1f1fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello There'"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# It returns a new string, but does not modify the original\n",
    "word = greeting.title()\n",
    "word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "1bbee50f-c11d-4f35-a9c8-8efd23b47df2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# List methods modify the original list\n",
    "groceries = [\"vinegar\", \"olives\", \"bread\"]\n",
    "varaible = groceries.append(\"apples\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "85592422-8273-4e3b-9d87-764ff83aacf2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['vinegar', 'olives', 'bread', 'apples']"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groceries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "9be44844-e1ce-4311-91e9-273863806992",
   "metadata": {},
   "outputs": [],
   "source": [
    "groceries.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "361c6974-1d89-4498-95d7-5d4edf9a87d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['apples', 'bread', 'olives', 'vinegar']"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groceries"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb570c33-8fb5-4409-9274-cab70e1860df",
   "metadata": {},
   "source": [
    "#### A list of methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "5ee5ece4-7983-42d7-a9ee-5e7dfa0cee3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__add__',\n",
       " '__class__',\n",
       " '__contains__',\n",
       " '__delattr__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__getnewargs__',\n",
       " '__getstate__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__len__',\n",
       " '__lt__',\n",
       " '__mod__',\n",
       " '__mul__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__rmod__',\n",
       " '__rmul__',\n",
       " '__setattr__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " 'capitalize',\n",
       " 'casefold',\n",
       " 'center',\n",
       " 'count',\n",
       " 'encode',\n",
       " 'endswith',\n",
       " 'expandtabs',\n",
       " 'find',\n",
       " 'format',\n",
       " 'format_map',\n",
       " 'index',\n",
       " 'isalnum',\n",
       " 'isalpha',\n",
       " 'isascii',\n",
       " 'isdecimal',\n",
       " 'isdigit',\n",
       " 'isidentifier',\n",
       " 'islower',\n",
       " 'isnumeric',\n",
       " 'isprintable',\n",
       " 'isspace',\n",
       " 'istitle',\n",
       " 'isupper',\n",
       " 'join',\n",
       " 'ljust',\n",
       " 'lower',\n",
       " 'lstrip',\n",
       " 'maketrans',\n",
       " 'partition',\n",
       " 'removeprefix',\n",
       " 'removesuffix',\n",
       " 'replace',\n",
       " 'rfind',\n",
       " 'rindex',\n",
       " 'rjust',\n",
       " 'rpartition',\n",
       " 'rsplit',\n",
       " 'rstrip',\n",
       " 'split',\n",
       " 'splitlines',\n",
       " 'startswith',\n",
       " 'strip',\n",
       " 'swapcase',\n",
       " 'title',\n",
       " 'translate',\n",
       " 'upper',\n",
       " 'zfill']"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "88949344-c8f7-402a-af63-aff1c4d23ec1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__add__',\n",
       " '__class__',\n",
       " '__contains__',\n",
       " '__delattr__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__getnewargs__',\n",
       " '__getstate__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__len__',\n",
       " '__lt__',\n",
       " '__mod__',\n",
       " '__mul__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__rmod__',\n",
       " '__rmul__',\n",
       " '__setattr__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " 'capitalize',\n",
       " 'casefold',\n",
       " 'center',\n",
       " 'count',\n",
       " 'encode',\n",
       " 'endswith',\n",
       " 'expandtabs',\n",
       " 'find',\n",
       " 'format',\n",
       " 'format_map',\n",
       " 'index',\n",
       " 'isalnum',\n",
       " 'isalpha',\n",
       " 'isascii',\n",
       " 'isdecimal',\n",
       " 'isdigit',\n",
       " 'isidentifier',\n",
       " 'islower',\n",
       " 'isnumeric',\n",
       " 'isprintable',\n",
       " 'isspace',\n",
       " 'istitle',\n",
       " 'isupper',\n",
       " 'join',\n",
       " 'ljust',\n",
       " 'lower',\n",
       " 'lstrip',\n",
       " 'maketrans',\n",
       " 'partition',\n",
       " 'removeprefix',\n",
       " 'removesuffix',\n",
       " 'replace',\n",
       " 'rfind',\n",
       " 'rindex',\n",
       " 'rjust',\n",
       " 'rpartition',\n",
       " 'rsplit',\n",
       " 'rstrip',\n",
       " 'split',\n",
       " 'splitlines',\n",
       " 'startswith',\n",
       " 'strip',\n",
       " 'swapcase',\n",
       " 'title',\n",
       " 'translate',\n",
       " 'upper',\n",
       " 'zfill']"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(\"hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "417d5fcc-cfc3-4fd5-a07d-776cfe6be616",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__add__',\n",
       " '__class__',\n",
       " '__class_getitem__',\n",
       " '__contains__',\n",
       " '__delattr__',\n",
       " '__delitem__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__getstate__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__iadd__',\n",
       " '__imul__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__len__',\n",
       " '__lt__',\n",
       " '__mul__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__reversed__',\n",
       " '__rmul__',\n",
       " '__setattr__',\n",
       " '__setitem__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " 'append',\n",
       " 'clear',\n",
       " 'copy',\n",
       " 'count',\n",
       " 'extend',\n",
       " 'index',\n",
       " 'insert',\n",
       " 'pop',\n",
       " 'remove',\n",
       " 'reverse',\n",
       " 'sort']"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "714a19de-d3c8-4a23-bbc9-e342d6cda069",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### How to create new methods?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdd10132-5b8d-4f93-bdff-ffb55fde5775",
   "metadata": {},
   "source": [
    "##### First, you need to learn how to create classes."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7d34254-47ed-443e-94a9-d20283eff6fc",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Lists and tuples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "72305388-99dd-4c19-97f8-67c01baf5761",
   "metadata": {},
   "outputs": [],
   "source": [
    "groceries = [\"vinegar\", \"olives\", \"bread\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "e7e4a34c-9077-43ff-90bb-ac5151eb08aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "values = (1920, 1080, \"grayscale\", \"JPG\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eda02e46-d1fd-4a72-b419-56fa5ad02289",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Like strings, tuples also have no methods that modify the original\n",
    "values.append()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88104ab8-5c86-4093-869f-9c94fe33c040",
   "metadata": {},
   "source": [
    "#### Indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "88cc6fd1-e897-4c69-ad71-824fb54a8c00",
   "metadata": {},
   "outputs": [],
   "source": [
    "string = \"vinegar\"\n",
    "groceries = [\"vinegar\", \"olives\", \"bread\"]\n",
    "values = (1920, 1080, \"grayscale\", \"JPG\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56d94a51-77f8-43bf-9d89-e7a1ae4841a3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "fc119b36-50a1-42d5-8f30-adb6293f58d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'vinegar'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groceries[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e10febd2-b21c-4684-a677-daeb83d0784d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'bread'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groceries[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "b26c0d3c-8e50-4c36-b940-0d35526de52d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'grayscale'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "values[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "d2544a55-427e-4c5f-bd0f-a9b697addc03",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'n'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "cb4bcabf-f35e-494b-84c1-309f442af828",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "6b8b9713-5e4c-49c8-bab3-75d04b16211d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1080, 'grayscale')"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "values[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "7dfbc7e1-f7bd-4ed0-8b8b-cc9ade0fe62a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1080, 'grayscale')"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "values[-3:-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c37190f7-db13-40ba-9cbc-7f21b99f47ba",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Dictionaries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "427a7ad9-e9b7-467d-90c0-bbf890c269fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "john = {\"first name\": \"John\", \"last name\": \"smith\", \"age\":40}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "8d673455-a7c1-44a7-ad19-b2c641bc25aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "persons1 = [{\"first name\": \"John\", \"last name\": \"smith\", \"age\":40}, \n",
    "           {\"first name\": \"laura\", \"last name\": \"eager\", \"age\":45},\n",
    "           {\"first name\": \"sim\", \"last name\": \"agraval\", \"age\":42}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "2b63d3f6-8e16-487c-97d3-fa954197f9e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "persons2 = {\"first name\": [\"john\", \"laura\", \"sim\"], \n",
    "           \"last name\": [\"smith\", \"eager\", \"age\"], \n",
    "           \"age\": [40, 45, 42]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "e22aa20a-8ffb-42c2-be9b-a2f7e952c4b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'smith'"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "john[\"last name\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "8c6c3608-a5c7-4ed0-861c-77e57e28128d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'sim'"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "persons1[2][\"first name\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "6672e38a-8f85-4e60-ae67-f6676167f826",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'sim'"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "persons[\"first name\"][2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13e21c94-33db-446b-b9dc-31311e9b3e63",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Code blocks"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e797cc92-6808-497c-8490-9769830d5b00",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### While-Loops"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a30bd64-14eb-4162-a56e-adf78b64efe2",
   "metadata": {},
   "outputs": [],
   "source": [
    "while True: \n",
    "    password = input(\"Enter password: \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "a342afe1-7f81-4d07-9a39-ba53e9e57737",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter password:  pass\n",
      "Enter password:  pass2\n",
      "Enter password:  pass1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Password is correct\n"
     ]
    }
   ],
   "source": [
    "while password != \"pass1\":\n",
    "    password = input(\"Enter password: \")\n",
    "\n",
    "print(\"Password is correct\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bece4d7d-5c6a-4c8f-81a0-55c28af9bebe",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### For-Loops"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "df19c20c-7ec6-4a66-94b7-ffe5c7496c24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "John\n",
      "Sim\n",
      "Spongy\n"
     ]
    }
   ],
   "source": [
    "usernames = [\"john\", \"sim\", \"spongy\"]\n",
    "for username in usernames:\n",
    "    print(username.capitalize())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55bbf83b-d1fd-4a2f-850e-543996fc8193",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Match-Case"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "2f7a63e9-6b2f-49af-9fbc-65ba1e3126d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter username:  sim\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome User\n"
     ]
    }
   ],
   "source": [
    "username = input(\"Enter username: \")\n",
    "\n",
    "match username:\n",
    "    case \"john\":\n",
    "        print(\"Welcome Admin\")\n",
    "    case \"sim\":\n",
    "        print(\"Welcome User\")\n",
    "    case \"spongy\":\n",
    "        print(\"Welcome Guest\")\n",
    "    case _:\n",
    "        print(\"Invalid username\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22ef95ee-d701-4775-be01-3f24ccc7ca6e",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### If-Elif-Else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8b9e5091-39c5-412f-b347-6cb73eeb98db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Password is strong\n"
     ]
    }
   ],
   "source": [
    "password = \"pass\"\n",
    "if len(password) > 3:\n",
    "    print(\"Password is strong\")\n",
    "else:\n",
    "    print(\"Password is weak\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cc1fed6a-ae13-4fac-b4ae-af12cdbdf447",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Password is strong\n"
     ]
    }
   ],
   "source": [
    "password = \"pass\"\n",
    "\n",
    "if len(password) > 3:\n",
    "    print(\"Password is strong\")\n",
    "elif len(username)==4:\n",
    "    print(\"Password is medium\")\n",
    "else:\n",
    "    print(\"Password is weak\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f169f6b-3b1b-4428-84f0-c5b6d476958d",
   "metadata": {
    "tags": []
   },
   "source": [
    "# f-strings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c9306b75-babb-4003-9adc-194509f82301",
   "metadata": {},
   "outputs": [],
   "source": [
    "first_name = \"naya\"\n",
    "last_name = \"anand\"\n",
    "message = f\"Hello {first_name.capitalize()} {last_name.capitalize()}! Have a nice day!\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "010130f8-1dc2-4b4e-aee0-27480fc614bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello Naya Anand! Have a nice day!'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "message"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "935abb64-eaa2-4ed5-b7d1-f648df777e5f",
   "metadata": {
    "tags": []
   },
   "source": [
    "# External Files"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a3e9b04-f72c-42ed-96bf-9071b90507e8",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Creating files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "63018afb-9044-46e0-af58-a85e8d10200a",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"book.txt\", \"w\") as file:\n",
    "    file.write(\"Hello there!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1bfda6a3-735d-462b-a014-917108680970",
   "metadata": {},
   "outputs": [],
   "source": [
    "content = \"\"\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n",
    "Sed viverra varius lorem sed convallis. Ut finibus arcu ac sem porta sodales. \n",
    "Nullam ut eleifend lacus. Sed et aliquam metus.\n",
    "\"\"\"\n",
    "\n",
    "with open(\"book.txt\", \"w\") as file:\n",
    "    file.write(content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "aab08cb0-dc74-43c4-a941-bde3a55b180f",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"weather.txt\", \"w\") as file:\n",
    "    file.writelines([\"Clouds\\n\", \"Sun\\n\", \"Sun\\n\", \"Rain\\n\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d62af956-71f2-419b-a1fa-218dd0046a64",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Reading files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3d3c7d4e-3f7a-4ec2-bb6a-ba00fe3b2741",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"book.txt\", \"r\") as file:\n",
    "    content = file.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "018f3167-93f6-427c-ab19-a01fccb54baf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nLorem ipsum dolor sit amet, consectetur adipiscing elit. \\nSed viverra varius lorem sed convallis. \\nUt finibus arcu ac sem porta sodales. Nullam ut eleifend lacus. \\nSed et aliquam metus.\\n'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "01150c4a-ae4b-4510-aad8-52c93ed830d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n",
      "Sed viverra varius lorem sed convallis. \n",
      "Ut finibus arcu ac sem porta sodales. Nullam ut eleifend lacus. \n",
      "Sed et aliquam metus.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "534ad7dd-0feb-4cb6-8a5e-a1ee8462c052",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"weather.txt\", \"r\") as file:\n",
    "    content = file.readlines()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0e21065e-e4da-49fa-9232-86e2fa0d9634",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Clouds\\n', 'Sun\\n', 'Sun\\n', 'Rain\\n']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "content"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f82ebd9-30be-4ae2-8af6-00fc571e2fe1",
   "metadata": {
    "tags": []
   },
   "source": [
    "# List Comprehensions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c3bdd3e9-9069-440f-9dd9-e9ec0434e4c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "clean_content = [item.strip(\"\\n\") for item in content]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "31c75093-601a-4360-932b-2314ef530941",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Clouds', 'Sun', 'Sun', 'Rain']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clean_content"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0f235cd-9b7b-4487-ba73-ed8333b218bb",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Errors"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b29ffc4-d5af-4d17-badd-5090666f1252",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Syntax Errors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "43ca03ac-16d3-4d75-8c24-6a0912aac3a3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "closing parenthesis ')' does not match opening parenthesis '[' (1587395620.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Cell \u001b[0;32mIn [27], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m    clean_content = [item.strip(\"\\n\") for item in content)\u001b[0m\n\u001b[0m                                                         ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m closing parenthesis ')' does not match opening parenthesis '['\n"
     ]
    }
   ],
   "source": [
    "clean_content = [item.strip(\"\\n\") for item in content)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82656ffa-41d7-4f63-b1c7-fbfee3cf7989",
   "metadata": {},
   "source": [
    "###### The error message is not always clear"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3f744e06-73da-4b19-abab-890b895a7c2a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "did you forget parentheses around the comprehension target? (4251457587.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Cell \u001b[0;32mIn [28], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m    clean_content = [item,strip(\"\\n\") for item in content]\u001b[0m\n\u001b[0m                     ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m did you forget parentheses around the comprehension target?\n"
     ]
    }
   ],
   "source": [
    "clean_content = [item,strip(\"\\n\") for item in content]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42aac7f6-c34d-4639-aa1d-3351947aae04",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Exceptions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "177c7894-392c-4e1a-9804-c8a2dd7d4e41",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'apple' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn [29], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m clean_content \u001b[38;5;241m=\u001b[39m [item\u001b[38;5;241m.\u001b[39mstrip(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m apple]\n",
      "\u001b[0;31mNameError\u001b[0m: name 'apple' is not defined"
     ]
    }
   ],
   "source": [
    "clean_content = [item.strip(\"\\n\") for item in apple]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e3708fe1-12a2-4c7a-968b-8827b41d7461",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'streap'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn [31], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m clean_content \u001b[38;5;241m=\u001b[39m [item\u001b[38;5;241m.\u001b[39mstreap(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m content]\n",
      "Cell \u001b[0;32mIn [31], line 1\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[0;32m----> 1\u001b[0m clean_content \u001b[38;5;241m=\u001b[39m [item\u001b[38;5;241m.\u001b[39mstreap(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m content]\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'str' object has no attribute 'streap'"
     ]
    }
   ],
   "source": [
    "clean_content = [item.streap(\"\\n\") for item in content]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "13887382-4223-460f-81c4-d29ac7f621d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter the year:  12.12.3001\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: '12.12.3001'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn [36], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m year_of_birth \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEnter the year: \u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[1;32m      2\u001b[0m current_year \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3221\u001b[39m\n\u001b[1;32m      3\u001b[0m age \u001b[38;5;241m=\u001b[39m current_year \u001b[38;5;241m-\u001b[39m year_of_birth\n",
      "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: '12.12.3001'"
     ]
    }
   ],
   "source": [
    "year_of_birth = int(input(\"Enter the year: \"))\n",
    "current_year = 3221\n",
    "age = current_year - year_of_birth\n",
    "print(age) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "7c1b8327-2724-4f62-b50e-85254cc923f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter the year:  year 3001\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The format should be YYYY\n"
     ]
    }
   ],
   "source": [
    "current_year = 3221 # Put code like this outside if you can\n",
    "\n",
    "try:\n",
    "    year_of_birth = int(input(\"Enter the year: \"))\n",
    "    age = current_year - year_of_birth\n",
    "    print(age)\n",
    "except ValueError:\n",
    "    print(\"The format should be YYYY\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11807499-91e9-412d-a770-93f69f723acb",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Try-except does not catch syntax errors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "4d344ae7-6e40-42e8-9f3c-cd1df495ff29",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax. Perhaps you forgot a comma? (1155276590.py, line 4)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Cell \u001b[0;32mIn [47], line 4\u001b[0;36m\u001b[0m\n\u001b[0;31m    year_of_birth = int(input(\"Enter the year: \")\u001b[0m\n\u001b[0m                        ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax. Perhaps you forgot a comma?\n"
     ]
    }
   ],
   "source": [
    "current_year = 3221 # Put code like this outside if you can\n",
    "\n",
    "try:\n",
    "    year_of_birth = int(input(\"Enter the year: \") \n",
    "    age = current_year - year_of_birth\n",
    "    print(age # Missing parenthesis\n",
    "except:\n",
    "    print(\"The format should be YYYY\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93e3b129-2c6a-45d2-985a-9df42c2e4756",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### When to use try-except and when to use if-elif-else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "81857ff3-db82-4949-854b-258ae3dd0654",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter the year:  2000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Age too big\n"
     ]
    }
   ],
   "source": [
    "current_year = 3221 # Put code like this outside if you can\n",
    "\n",
    "try:\n",
    "    year_of_birth = int(input(\"Enter the year: \"))\n",
    "    age = current_year - year_of_birth\n",
    "    if age < 150:\n",
    "        print(age)\n",
    "    else:\n",
    "        print(\"Age too big\")\n",
    "except:\n",
    "    print(\"The format should be YYYY\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87bbfe67-b295-4f28-b96d-0525aa206c12",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Comments and doc strings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "cf8c4a60-c4dc-4ebf-938a-250be58c2a26",
   "metadata": {},
   "outputs": [],
   "source": [
    "def area(a, b):\n",
    "    \"\"\"Calculate the area of a rectangle\n",
    "    given its two sides\n",
    "    \"\"\"\n",
    "    return a * b\n",
    "\n",
    "rectangle_area = area(10, 20)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fd043f1-3ea5-4fbe-85d6-ac1c857dec93",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Modules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88a605cb-4341-408a-a20f-e50b6464a54c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import myfile\n",
    "\n",
    "rectangle_area = myfile.area(10, 20)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c66313bf-e003-41db-9087-71b22f322744",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Standard libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "fadf64ac-420a-4ad1-a4a6-ed157cd65b09",
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "c68ecc68-5a59-4f21-8727-5e35dc3f15cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['weather.txt', 'book.txt']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "glob.glob(\"*.txt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "c409f7d8-7b5b-4bc0-a964-a4c1b20864f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = requests.get(\"https://example.com\")\n",
    "content = response.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "65927178-cc88-44b9-b460-411f7132c23e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<!doctype html>\\n<html>\\n<head>\\n    <title>Example Domain</title>\\n\\n    <meta charset=\"utf-8\" />\\n    <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\\n    <style type=\"text/css\">\\n    body {\\n        background-color: #f0f0f2;\\n        margin: 0;\\n        padding: 0;\\n        font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\\n        \\n    }\\n    div {\\n        width: 600px;\\n        margin: 5em auto;\\n        padding: 2em;\\n        background-color: #fdfdff;\\n        border-radius: 0.5em;\\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\\n    }\\n    a:link, a:visited {\\n        color: #38488f;\\n        text-decoration: none;\\n    }\\n    @media (max-width: 700px) {\\n        div {\\n            margin: 0 auto;\\n            width: auto;\\n        }\\n    }\\n    </style>    \\n</head>\\n\\n<body>\\n<div>\\n    <h1>Example Domain</h1>\\n    <p>This domain is for use in illustrative examples in documents. You may use this\\n    domain in literature without prior coordination or asking for permission.</p>\\n    <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\\n</div>\\n</body>\\n</html>\\n'"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "content"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa48daae-0bbc-4888-9de4-25c06689530a",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Third party libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f0ec488-2c12-4fc7-b8aa-860abd17fb5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip insall library_name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce509f45-3b7e-4743-bc08-572b69a4b857",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Web apps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ac422ed-196c-4cb4-a70b-5f787d8168c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "streamlit"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1963cf45-9ae6-4449-b10a-b669290aa3f0",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Desktop GUI app"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9859a543-8e01-43ee-a5f0-b2a499810276",
   "metadata": {},
   "outputs": [],
   "source": [
    "PySimpleGUI"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
