Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tamoghna-Saha/1a8e7ffde9e67359f58aa527fb45c91d to your computer and use it in GitHub Desktop.
Save Tamoghna-Saha/1a8e7ffde9e67359f58aa527fb45c91d to your computer and use it in GitHub Desktop.
Python Notebook | Intermediate | Part 1.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-28T13:09:39.903487Z",
"start_time": "2018-09-28T13:09:39.896175Z"
}
},
"cell_type": "markdown",
"source": "# Table of Content:\n* [Small test](#test)\n* [More Data Types](#more_types)\n* [Conditional statements, Loops](#loops)\n* [File I/O](#io)\n* [Exception Handling](#handling)\n* [Answers](#answer)"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-09T11:16:05.158612Z",
"start_time": "2018-11-09T11:16:05.152769Z"
},
"trusted": true
},
"cell_type": "code",
"source": "# Small test\n\ndef operation(x, y):\n return x+y\n\ndef another_operation(func, x, y):\n return func(func(x,y), func(x,y))\n\na = 5\nb = 25\n\nprint(another_operation(operation, a, b))",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# More Data Types <a name=\"more_types\"></a>\n\n__List of immutable objects:__\n* bool\n* int\n* float\n* str\n* tuple\n* frozenset\n\n__List of mutable objects:__\n* list\n* set\n* dict\n\n## List\n\nList is a type of __mutable__ object in Python used to store an __indexed__ list of item. It is created using __square brackets__ with commas separating the items. A certain item from the list can be accessed using it's index number.\n\nAn empty list is created using an empty pair of square brackets.\n\nA list can contain items of a __single item type or multiple item type__. A list within a list is also possible which is used to represent 2D grids as Python, by default, lacks multi-dimensional array feature. But this can be achieved using __numpy__ which we will discuss in our Advanced Notebook.\n\n__NOTE: Strings can be indexed like a list__."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:41.954641Z",
"start_time": "2018-11-12T08:30:41.936057Z"
},
"trusted": true
},
"cell_type": "code",
"source": "empty_list = []\n\nwords = ['Python',3.6,['Up Next','Tuple']]\n\nprint(words[0])\nprint(words[2][1])\n\nprint(words[1])\nwords[1]=2.7\nprint(words)\n\n## accessing items of string by index\nshort_form = \"User Defined Function\"\nprint(\"In our last class, we went through {}{}{}\".format(short_form[0], short_form[5], short_form[13]))",
"execution_count": 1,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Python\nTuple\n3.6\n['Python', 2.7, ['Up Next', 'Tuple']]\nIn our last class, we went through UDF\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:42.722966Z",
"start_time": "2018-11-12T08:30:42.714830Z"
},
"trusted": true
},
"cell_type": "code",
"source": "## basic list operations\nnum_list = [1,2,3]\nprint(num_list + [4,5,6])\nprint(num_list * 2)\nprint(4 in num_list)\nprint(9 not in num_list)\nprint(not 1 in num_list)",
"execution_count": 2,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "[1, 2, 3, 4, 5, 6]\n[1, 2, 3, 1, 2, 3]\nFalse\nTrue\nFalse\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:43.694098Z",
"start_time": "2018-11-12T08:30:43.682314Z"
},
"trusted": true
},
"cell_type": "code",
"source": "# list functions and methods\nnum = [1,2,3]\nnum.append(4)\nnum.append([5,6])\nprint(num)\n\nprint(len(num))\n\nnum.extend([7,8,9])\nprint(num)\nprint(len(num))\n\nindex = 2\nnum.insert(index, 2.5)\nprint(num)\n\nprint(\"-----------------------------\")\n\nprint(num.index(3))\nprint(num.index(2.0))\n\nnum.remove([5,6])\nnum.pop()\nprint(num)\n\nprint(max(num))\nprint(num.count(5))\n\nnum.reverse()\nprint(num)",
"execution_count": 3,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "[1, 2, 3, 4, [5, 6]]\n5\n[1, 2, 3, 4, [5, 6], 7, 8, 9]\n8\n[1, 2, 2.5, 3, 4, [5, 6], 7, 8, 9]\n-----------------------------\n3\n1\n[1, 2, 2.5, 3, 4, 7, 8]\n8\n0\n[8, 7, 4, 3, 2.5, 2, 1]\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Tuple\n\nTuple is a __immutable__ Python object created using __Parentheses__ with commas separating the items which can be accessed using it's index number.\n\nIt is just like list, except __you cannot modify or re-assign a value in the tuple. It will throw TypeError__.\n\nAn empty tuple can also be created in the same way you create empty list.\n\n__NOTE: Tuples can also be created without using Parentheses, simply separated by commas.__\n\n### But when should we put parenthesis on tuples, and when we shouldn't?\n\nAnswer: We use parentheses for __nested tuple__."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:46.092505Z",
"start_time": "2018-11-12T08:30:45.960145Z"
},
"trusted": true
},
"cell_type": "code",
"source": "empty_tuple = ()\n\nmy_tuple = (\"is\", \"my\", \"tuple\")\nprint(my_tuple[2])\n\nalso_my_tuple = 'is', 'this', 'one'\nprint(also_my_tuple[3])",
"execution_count": 4,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "tuple\n"
},
{
"ename": "IndexError",
"evalue": "tuple index out of range",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-4-7a7df2b84a95>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0malso_my_tuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'is'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'this'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'one'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0malso_my_tuple\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m: tuple index out of range"
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Dictionaries\n\nDictionaries are data structures used __to map keys to values__. Just like list, they are __mutable__ and made using __curly brackets__. \n\nDictionaries can be indexed in the same way as lists, __using square brackets containing keys__. Trying to index a key that isn't a part of the dictionary returns a __KeyError__.\n\nThe useful dictionary method is __get__. It does same thing as indexing, but if the key is not found in the dictionary, it returns __None__ instead of throwing any error.\n\n__NOTE: Only immutable objects can be used as keys to dictionaries.__"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:49.270546Z",
"start_time": "2018-11-12T08:30:49.255480Z"
},
"trusted": true
},
"cell_type": "code",
"source": "empty_dict = {}\n\nmy_dict = {\"Joker\":'Why so serious?', \"Bane\": [1,2,3], \"Scarecrow\": 0.05}\nprint(my_dict[\"Joker\"])\n\nmy_dict_again = {(1,2,3):[1,2,3], ('a','b','c'):['a','b','c']}\nprint(my_dict_again[(1,2,3)])\n\nmy_dict_again[4] = 'd'\nprint(my_dict_again)\n\nprint(empty_dict[0])",
"execution_count": 5,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Why so serious?\n[1, 2, 3]\n{(1, 2, 3): [1, 2, 3], ('a', 'b', 'c'): ['a', 'b', 'c'], 4: 'd'}\n"
},
{
"ename": "KeyError",
"evalue": "0",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-75e3176fb6bc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_dict_again\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mempty_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m: 0"
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "__Quick Question: How to check whether a variable is mutable or not?__ [Answer](#ans1)"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:53.577427Z",
"start_time": "2018-11-12T08:30:53.561225Z"
},
"trusted": true
},
"cell_type": "code",
"source": "my_dict_error = {[1,2,3]:'a',}",
"execution_count": 6,
"outputs": [
{
"ename": "TypeError",
"evalue": "unhashable type: 'list'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-859c69ec502a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmy_dict_error\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m'a'\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: unhashable type: 'list'"
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### What does this error mean?\nAn object is __hashable__ if it has a hash value which never changes during its lifetime (it needs hash() method). List is unhashable because it's content can change over its lifetime.\n\n__NOTE__: Don't know about Hash function? Think about it as the fingerprint of a file in an encrypted format. For details, search in Google."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:56.618982Z",
"start_time": "2018-11-12T08:30:56.610563Z"
},
"trusted": true
},
"cell_type": "code",
"source": "# How about a dictionary within a dictionary?\nmy_dict_yet_again = {0:\"infinity\", 1:{'a':[1,2]}, 'b':{2: (3,4)}}\nprint(my_dict_yet_again)\nprint(my_dict_yet_again[1]['a'])\n\n# Some dictionary functions\nprint(1 in my_dict_yet_again) # check if a key is available in the dictionary\nprint({'a':[1,2]} in my_dict_yet_again.values()) #check if the value is available in the dictionary\n\nmy_dict_yet_again[True]=False\nprint(my_dict_yet_again)\n\nprint(my_dict_yet_again.get(1)) # get method\nprint(my_dict_yet_again.get(2))\nprint(my_dict_yet_again.get(\"True\",\"True string is not available as key\"))",
"execution_count": 7,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "{0: 'infinity', 1: {'a': [1, 2]}, 'b': {2: (3, 4)}}\n[1, 2]\nTrue\nTrue\n{0: 'infinity', 1: False, 'b': {2: (3, 4)}}\nFalse\nNone\nTrue string is not available as key\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Set and Frozenset\n\nSets are Python object similar to lists or dictionaries. They are created using __curly braces__ or the __set function__. They are unordered, which means that they __can't be indexed__. They __cannot contain duplicate elements__. Due to the way they're stored, it's __faster to check whether an item is part of a set__, rather than part of a list.\n\nInstead of using __append__ to add an item to a set, we use __add__. The method __remove__ removes a specific element from a set but __pop__ removes an arbitrary element."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:30:59.063383Z",
"start_time": "2018-11-12T08:30:59.054381Z"
},
"trusted": true
},
"cell_type": "code",
"source": "my_set = set((2.7,\"3.6\"))\nalso_my_set = {2.7, 3.6}\nmy_frozenset = frozenset((\"Python\",\"2.7\"))\n\nmy_set.add(6)\nprint(my_set)\nprint(my_frozenset)\n\nmy_set.remove(2.7)\nmy_set.pop()\nprint(my_set)\n\n# some additional operations\nfirst = {1, 2, 3, 4, 5, 6}\nsecond = {4, 5, 6, 7, 8, 9}\n\nprint(first | second)\nprint(first & second)\nprint(first - second)\nprint(second - first)\nprint(first ^ second)",
"execution_count": 8,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "{2.7, '3.6', 6}\nfrozenset({'2.7', 'Python'})\n{6}\n{1, 2, 3, 4, 5, 6, 7, 8, 9}\n{4, 5, 6}\n{1, 2, 3}\n{8, 9, 7}\n{1, 2, 3, 7, 8, 9}\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### So, what are the operations that can be perfomed on mutable and immutable objects in Python?\n\n#### Both mutable and immutable\n\n| Operation | Result |\n|:---:|:---:|\n| len(s) | cardinality of set s |\n| x in s | test x for membership in s |\n| x not in s | test x for non-membership in s |\n| s.issubset(t)\t| test whether every element in s is in t |\n| s.issuperset(t) | test whether every element in t is in s |\n| s.union(t) | new set with elements from both s and t |\n| s.intersection(t) | new set with elements common to s and t |\n| s.difference(t) | new set with elements in s but not in t |\n| s.symmetric_difference(t)\t| new set with elements in either s or t but not both |\n| s.copy() | new set with a shallow copy of s |\n\n#### Only mutable\n\n| Operation | Result |\n|:---:|:---:|\n| s.update(t) | update set s, adding elements from t\n| s.intersection_update(t)\t| update set s, keeping only elements found in both s and t\n| s.difference_update(t) | update set s, removing elements found in t\n| s.symmetric_difference_update(t) | update set s, keeping only elements found in either s or t but not in both\n| s.add(x) | add element x to set s\n| s.remove(x) | remove x from set s; raises KeyError if not present\n| s.discard(x) | removes x from set s if present\n| s.pop() | remove and return an arbitrary element from s; raises KeyError if empty\n| s.clear() | remove all elements from set s\n\n### Also, when to use these data structures?\n\nWhen to use a __dictionary__:\n- When you need a logical association between a key:value pair.\n- When you need fast lookup for your data, based on a custom key.\n- When your data is being constantly modified.\n\nWhen to use the __other types__:\n- Use __lists__ if you have a collection of data that does not need random access. Try to choose lists when you need a simple, iterable collection that is modified frequently.\n- Use a __set__ if you need uniqueness for the elements.\n- Use __tuples__ when your data cannot change."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Conditional statements, loops <a name=\"loops\"></a>\n\n## if, elif, else\n\nPython uses __if__ statements to run code if a certain condition holds _True_, otherwise they aren't.\n\n__NOTE__: Python uses __indentation__ (white space at the beginning of a line) to delimit blocks of code. Other languages, such as C, use curly braces to accomplish this, but in Python, indentation is mandatory; programs won't work without it.\n\n__To perform more complex checks__, _if_ statements can be __nested__, one inside the other. This means that the inner _if_ statement is the statement part of the outer one.\n\nAn __else__ statement follows an _if_ statement, and contains code that is called when the _if_ statement evaluates to _False_.\n\nThe __elif__ (short for else if) statement is a shortcut to use when __chaining if and else statements__. A series of _if elif_ statements can have a final else block, which is called if none of the _if_ or _elif_ expressions is _True_."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:05.625335Z",
"start_time": "2018-11-12T08:31:02.738158Z"
},
"trusted": true
},
"cell_type": "code",
"source": "num = int(input(\"Enter a number from 0 to 9: \"))\n\nif num == 3:\n print(\"You got 3\")\nelif num == 6:\n print(\"Number is 6\")\nelif num == 9:\n print(\"Looks like 9\")\nelse:\n print(\"`If you knew the magnificence of the three, six and nine, you would have a key to the universe.` ~ Tesla\")",
"execution_count": 9,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Enter a number from 0 to 9: 5\n`If you knew the magnificence of the three, six and nine, you would have a key to the universe.` ~ Tesla\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## for\n\nThe __for__ loop is commonly used to repeat some code a certain number of times on an object known as __iterator__. This is done by combining for loops with __range__ objects."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:11.868808Z",
"start_time": "2018-11-12T08:31:11.858478Z"
},
"trusted": true
},
"cell_type": "code",
"source": "for i in range(5):\n if i < 3:\n print(\"hello!\")\n else:\n print(\"world\")\n \nprint(\"-----------------\")\n \nfor i in range(2,12,3):\n print(i)",
"execution_count": 10,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "hello!\nhello!\nhello!\nworld\nworld\n-----------------\n2\n5\n8\n11\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Two questions for you guys\n\n1. Ever wondered why people use _i_ in for loop?\n2. What is the difference between __range(x)__ and __list(range(x))__?"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:17.127177Z",
"start_time": "2018-11-12T08:31:17.070523Z"
},
"trusted": true
},
"cell_type": "code",
"source": "?range\n\nprint(list(range(5)))\nprint(range(5))",
"execution_count": 11,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "[0, 1, 2, 3, 4]\nrange(0, 5)\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Answer\n\n1. The i stands for the item to be accessed from any iterable or range object.\n\n2. When you execute _?range_, it will say that range returns an object that produces a sequence of integers from start (inclusive) to stop (exclusive) by step __without assigning indexes to the values__. Rather, it generates only one number at a time, relying on a __for__ loop to request for the next item in the range to be seen. However, __list(range()) does assign indices__ and hence allows you to see the full sequence of the numbers immediately, without the assistance of a _for_ loop.\n\n### Enumerate\n__Enumerate__ is a built-in function of Python which captures the index value of any iterable items while iterating over a for loop. It has an optional argument that allows us to tell _enumerate_ from __where to start the index__."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:24.241875Z",
"start_time": "2018-11-12T08:31:24.236512Z"
},
"trusted": true
},
"cell_type": "code",
"source": "my_list = ('apple', 'banana', 'grapes', 'pear')\ncounter_list = list(enumerate(my_list, 1)) # 1 is the argument to indicate the starting value of the index\nprint(counter_list)",
"execution_count": 12,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "[(1, 'apple'), (2, 'banana'), (3, 'grapes'), (4, 'pear')]\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## while\n\nAn __if__ statement is __run once__ if its condition evaluates to _True_. A __while__ statement is similar, except that it can be __run more than once__. The statements inside it are repeatedly executed, as long as the condition holds _True_. Once it evaluates to False, the next section of code is executed.\n\nThe __infinite loop__ is a special kind of while loop where the condition is always True and never stops iterating.\n\nTo end a while loop prematurely, the __break__ statement can be used inside the loop.\n\nWhen a continue statement is encountered, the code flow jumps back to the top of the loop, rather than stopping it. Basically it __stops the current iteration__ and continues with the next one."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:32.490117Z",
"start_time": "2018-11-12T08:31:26.469884Z"
},
"trusted": true
},
"cell_type": "code",
"source": "import time\n\nmewtwo_cp = 30\numbreon_dark_pulse = 3\nfight = True\n\nprint(\"You attacked Mewtwo! CP left: {}\".format(mewtwo_cp))\n\nwhile fight:\n print(\"Umbreon used Dark Pulse!\\n\")\n mewtwo_cp = mewtwo_cp - umbreon_dark_pulse\n \n if mewtwo_cp == 15:\n print(\"He's halfway dead!\") \n continue\n elif mewtwo_cp == 9: \n print(\"Take him down!\")\n continue\n elif mewtwo_cp == 3:\n print(\"Now's your chance\") \n continue\n \n if mewtwo_cp <= 0:\n print(\"Dead!\")\n break\n \n print(\"Mewtwo CP left: {}\".format(mewtwo_cp))\n time.sleep(1)\n \nprint(\"Congrats! Your Umbreon won.\")",
"execution_count": 13,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "You attacked Mewtwo! CP left: 30\nUmbreon used Dark Pulse!\n\nMewtwo CP left: 27\nUmbreon used Dark Pulse!\n\nMewtwo CP left: 24\nUmbreon used Dark Pulse!\n\nMewtwo CP left: 21\nUmbreon used Dark Pulse!\n\nMewtwo CP left: 18\nUmbreon used Dark Pulse!\n\nHe's halfway dead!\nUmbreon used Dark Pulse!\n\nMewtwo CP left: 12\nUmbreon used Dark Pulse!\n\nTake him down!\nUmbreon used Dark Pulse!\n\nMewtwo CP left: 6\nUmbreon used Dark Pulse!\n\nNow's your chance\nUmbreon used Dark Pulse!\n\nDead!\nCongrats! Your Umbreon won.\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# File I/O <a name=\"io\"></a>\n\nPython can be used to __read__ and __write__ the contents of files. Text files are the easiest to manipulate.\n\n### open\nBefore a file can be edited, it must be _opened_, using the __open__ function. The __argument__ of the open function is the _path to the file_. If the file is in the current working directory of the program, you can specify only its name.\n\n### mode\nThere are __mode__ used to open a file by applying a _second argument_ to the open function.\n* \"r\" means open in __read__ mode, which is the default.\n* \"w\" means __write__ mode, for rewriting the contents of a file.\n* \"a\" means __append__ mode, for adding new content to the end of the file.\n* \"b\" means __binary__ mode, which is used for non-text files (such as image and sound files).\n\n### read\nThe contents of a file that has been opened in text mode can be read using the __read__ method. To __read only a certain amount of a file, you can provide a number as an argument__ to the read function. This determines the __number of bytes__ that should be read.\n\nAfter all contents in a file have been read, any attempts to read further from that file will return an _empty string_, because you are trying to read __from the end of the file__. \n\nTo retrieve __each line__ in a file, you can use the __readlines__ method to _return a list in which each element is a line in the file_.\n\n__NOTE__: There is a __readline__ and a __readlines__ method. _readline()_ reads one line character at a time, _readlines()_ reads in the whole file at once and splits it by line.\n\n### write\nTo write to files we use the __write__ method, which writes a string to the file. The \"w\" mode will _create a file, if it does not already exist_. When a file is opened in write mode, the file's __existing content is deleted__. The write method __returns the number of bytes__ written to a file, if successful.\n\n__NOTE__: If you need to write anything other than string on a file, it has to be converted to a string first.\n\n### close\nOnce a file has been opened and used, it should be closed which is done with the __close__ method of the file object.\n\n### Alternative approach of file access\nAn alternative way of doing it is using __with__ statements. This creates a temporary variable (often called __f__), which is only accessible in the indented block of the with statement. The file is __automatically closed__ at the end of the with statement, even if exceptions occur within it."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:39.395932Z",
"start_time": "2018-11-12T08:31:39.387170Z"
},
"scrolled": false,
"trusted": true
},
"cell_type": "code",
"source": "file = open(\"def_NN.txt\", \"r\")\nprint(\"------- Reading the content -------\\n\")\nfile_content = file.read()\n\nprint(file_content)\nprint(\"------- Re-reading -------\")\nprint(file.read())\nprint(\"------- Finished! --------\\n\")\nprint(\"------- Closing the file -------\")\nfile.close()\n\n# try readlines",
"execution_count": 14,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "------- Reading the content -------\n\nWhat is Neural Network?\nA neural network is a processing unit that is capable to store knowledge and apply it to make predictions. A neural network mimics the brain in a way where the network acquires knowledge from its environment through a learning process. Then, intervention connection strengths known as synaptic weights are used to store the acquired knowledge. In the learning process, the synaptic weights of the network are modified in such a way so as to attain the desired objective.\n\nA neural network architecture comprises of 3 types of layers:\n\nInput Layer: The first layer in the network which receives input (training observations) and passed to the next hidden layer(s)\nHidden Layer: The intermediate processing layer(s) which perform specific tasks on the incoming data and pass on the output generated by them to the next output layer\nOutput Layer: The final layer of the network which generates the desired output\nEach of these layers are composed of Perceptrons which is analogous to the neuron of the our nervous system.\n\n------- Re-reading -------\n\n------- Finished! --------\n\n------- Closing the file -------\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:42.684908Z",
"start_time": "2018-11-12T08:31:42.677665Z"
},
"trusted": true
},
"cell_type": "code",
"source": "file = open(\"joker.txt\", \"r\")\nprint(\"------- Reading initial contents ------- \\n\")\nprint(file.read())\nprint(\"------- Finished ------- \\n\")\nfile.close()\n\nfile = open(\"joker.txt\", \"w\")\namount_written = file.write(\"I believe whatever doesn't kill you simply makes you...stranger.\")\nprint(\"Amount of text written: {}\\n\".format(amount_written))\nfile.close()\n\nfile = open(\"joker.txt\", \"r\")\nprint(\"------- Reading new contents ------- \\n\")\nprint(file.read())\nprint(\"\\n ------- Finished -------\")\nfile.close()",
"execution_count": 15,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "------- Reading initial contents ------- \n\nYou see, in their last moment, people show you who they really are.\n\n------- Finished ------- \n\nAmount of text written: 64\n\n------- Reading new contents ------- \n\nI believe whatever doesn't kill you simply makes you...stranger.\n\n ------- Finished -------\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:46.179847Z",
"start_time": "2018-11-12T08:31:46.173463Z"
},
"trusted": true
},
"cell_type": "code",
"source": "# alternative approach\nwith open(\"def_NN.txt\") as f:\n print(f.read())",
"execution_count": 16,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "What is Neural Network?\nA neural network is a processing unit that is capable to store knowledge and apply it to make predictions. A neural network mimics the brain in a way where the network acquires knowledge from its environment through a learning process. Then, intervention connection strengths known as synaptic weights are used to store the acquired knowledge. In the learning process, the synaptic weights of the network are modified in such a way so as to attain the desired objective.\n\nA neural network architecture comprises of 3 types of layers:\n\nInput Layer: The first layer in the network which receives input (training observations) and passed to the next hidden layer(s)\nHidden Layer: The intermediate processing layer(s) which perform specific tasks on the incoming data and pass on the output generated by them to the next output layer\nOutput Layer: The final layer of the network which generates the desired output\nEach of these layers are composed of Perceptrons which is analogous to the neuron of the our nervous system.\n\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Exception Handling <a name=\"handling\"></a>\n\n## Exception\n\n__Exception__ occur when something goes wrong due to incorrect code syntax or logic or input. When an exception occurs, the program immediately stops and doesn't executes any lines further.\n\n_Different exceptions are raised for different reasons._ Some common exceptions are listed below:\n* __ImportError__: an import fails\n* __IndexError__: a list is indexed with an out-of-range number\n* __NameError__: an unknown variable is used\n* __SyntaxError__: the code can't be parsed or processed properly\n* __TypeError__: a function is called on a value of an inappropriate type\n* __ValueError__: a function is called on a value of the correct type, but with an inappropriate value\n\nThird-party libraries and modules define their own exceptions. Learn more about built-in exceptions [here](https://docs.python.org/3.7/library/exceptions.html)\n\nHere are some examples of different built-in exceptions."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "```\n>>> list=[1,2,3] \n>>> print(list[3])\nTraceback (most recent call last): File \"<stdin>\", line 1, in <module> \nIndexError: list index out of range \n\n>>> printf(a)\nFile \"<stdin>\", line 1 \nprintf a \n ^ \nSyntaxError: invalid syntax\n\n>>> print(a)\nTraceback (most recent call last): File \"<stdin>\", line 1, in <module> \nNameError: name 'a' is not defined \n\n>>> import tk \nTraceback (most recent call last): File \"<stdin>\", line 1, in <module> \nImportError: No module named tk \n\n>>> a=2+\"hello\"\nTraceback (most recent call last): File \"<stdin>\", line 1, in <module> \nTypeError: unsupported operand type(s) for +: 'int' and 'str' \n\n>>> list.remove(0) \nTraceback (most recent call last): File \"<stdin>\", line 1, in <module> \nValueError: list.remove(x): x not in list\n```"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Exception Handling\n\nTo handle exceptions and call code when an exception occurs, we have to use a __try/except__ statement. \n\n### try-except\n\nThe __try__ block contains code that might throw an exception. If that exception occurs, the code in the try block stops executing, and the code in the __except__ block is run. If no error occurs, the code in the except block doesn't run.\n\nA try statement can have multiple different except blocks to handle different exceptions. _Multiple exceptions can also be put into a single except block using __parentheses__,_ to have the except block handle all of them.\n\nAn except statement without any exception specified will catch all errors. __However, this kind of coding should be avoided.__ If you do this, you are going against the zen of Python.\n\nException handling is particularly useful when\n* dealing with user input\n* sending stuff over network or saving large amounts of data, since issues happening with hardware like losing power or signal problems can happen"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:51.294938Z",
"start_time": "2018-11-12T08:31:51.286130Z"
},
"trusted": true
},
"cell_type": "code",
"source": "try:\n variable = 10\n print(variable + \"hello\")\n num1 = 7\n num2 = 0\n print(num1 / num2)\n print(\"Done calculation\")\nexcept ZeroDivisionError:\n print(\"An error occurred due to zero division\")\nexcept (ValueError, TypeError):\n print(\"ERROR!\")",
"execution_count": 17,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "ERROR!\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-08T07:02:27.162117Z",
"start_time": "2018-11-08T07:02:27.157110Z"
}
},
"cell_type": "markdown",
"source": "__If we do not know what possible exceptions will arise, what do we do?__ [Answer](#ans2)\n\n### raise\nWe can use __raise__ to throw an exception __if a condition occurs__. The statement can be complemented with a custom exception."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:31:54.290849Z",
"start_time": "2018-11-12T08:31:54.286373Z"
},
"trusted": true
},
"cell_type": "code",
"source": "x = 2\nif x > 5:\n raise Exception('x should not exceed 5. The value of x was: {}'.format(x))",
"execution_count": 18,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### else and finally\n\nHere using the else statement, you can instruct a program to execute a certain block of code __only in the absence of exceptions__.\n\nTo ensure some code runs no matter what errors occur, you can use a __finally__ statement. The finally statement is placed at the bottom of a try/except statement and else statement, if any.\n\n![try_except_else_finally](Photos/try_except_else_finally.png)"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:32:26.052288Z",
"start_time": "2018-11-12T08:32:26.044490Z"
},
"trusted": true
},
"cell_type": "code",
"source": "try:\n num_1 = 2\n num_2 = 5\n print(num_1/num_2)\nexcept ZeroDivisionError as error:\n print(error)\nelse:\n try:\n with open('joker.txt') as file:\n read_data = file.readline()\n print(read_data)\n except FileNotFoundError as fnf_error:\n print(fnf_error)\nfinally:\n print('Getting printed irrespective of any exceptions.')",
"execution_count": 19,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "0.4\nI believe whatever doesn't kill you simply makes you...stranger.\nGetting printed irrespective of any exceptions.\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:32:28.569649Z",
"start_time": "2018-11-12T08:32:28.550233Z"
},
"trusted": true
},
"cell_type": "code",
"source": "try:\n print(1)\n print(10 / 0)\nexcept ZeroDivisionError:\n print(error)\nfinally:\n print(\"This is executed last!\")",
"execution_count": 20,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "1\nThis is executed last!\n"
},
{
"ename": "NameError",
"evalue": "name 'error' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-20-b26411555290>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mZeroDivisionError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-20-b26411555290>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mZeroDivisionError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merror\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"This is executed last!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'error' is not defined"
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "__Why the exceptions messages are printed at the end of the output, not between \"1\" and \"This is executed last\"?__\n\nWhile catching the error for _print(10 / 0)_ the system found another exception in the __except__ block, the undeclared variable _error_ raising __NameError__ exception. So nothing was printed. This inner _NameError_ exception was uncaught by program and can only printed after finally block."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Assesrtion\n\nAn __assertion is a sanity-check__ where an expression is tested, and if the result comes up false, an exception is raised. When it encounters an assert statement, Python evaluates the accompanying expression, which is expected to be true. If the expression is false, Python raises an __AssertionError__ exception.\n\nAssertionError exceptions can be caught and handled like any other exception using the try-except statement, but if not handled, this type of exception will terminate the program.\n\n__But what makes assertion different from try/except?__ [Answer](#ans3)"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:32:32.004913Z",
"start_time": "2018-11-12T08:32:31.982639Z"
},
"trusted": true
},
"cell_type": "code",
"source": "def KelvinToFahrenheit(temp):\n assert (temp >= 0),\"Colder than absolute zero? Go back to school. -_-\"\n return ((temp - 273)*1.8) + 32\n\nprint(KelvinToFahrenheit(273))\nprint(KelvinToFahrenheit(-5))\nprint(KelvinToFahrenheit(373))",
"execution_count": 21,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "32.0\n"
},
{
"ename": "AssertionError",
"evalue": "Colder than absolute zero? Go back to school. -_-",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-21-832b1596a334>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mKelvinToFahrenheit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m273\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mKelvinToFahrenheit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mKelvinToFahrenheit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m373\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-21-832b1596a334>\u001b[0m in \u001b[0;36mKelvinToFahrenheit\u001b[0;34m(temp)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mKelvinToFahrenheit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtemp\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mtemp\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"Colder than absolute zero? Go back to school. -_-\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtemp\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;36m273\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m1.8\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m32\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mKelvinToFahrenheit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m273\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAssertionError\u001b[0m: Colder than absolute zero? Go back to school. -_-"
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Answers <a name=\"answer\"></a>"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Q1 <a name=\"ans1\"></a>\n\n__Copy the variable to a new variable and then change the new variable.__ Let us discuss it with an example."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:32:34.246528Z",
"start_time": "2018-11-12T08:32:34.241265Z"
},
"trusted": true
},
"cell_type": "code",
"source": "var_1 = 6\nvar_2 = var_1\nvar_1 = 9\n\nprint(\"var_1: {}\".format(var_1))\nprint(\"var_2: {}\".format(var_2))\n\nlst_1 = [1,2,3]\nlst_2 = lst_1\nlst_1.append(4)\n\nprint(\"lst_1: {}\".format(lst_1))\nprint(\"lst_2: {}\".format(lst_2))",
"execution_count": 22,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "var_1: 9\nvar_2: 6\nlst_1: [1, 2, 3, 4]\nlst_2: [1, 2, 3, 4]\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "__Conclusion:__ Integers are immutable since a change in var_1 was not reflected in var_2 but in case of list, there was a change making them mutable.\n\nThis is happening because when you create a list and assign it to a variable (__lst_1__), you have to think of this variable as __POINTING to the list rather than being EQUAL to it__. Whenever you assign another variable (__lst_2__) to the one you already have assigned the list, __both variables point to the SAME list object__. _Any list modifications will affect ALL variables pointing to it_."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Q2 <a name=\"ans2\"></a>\n\nCatch each exception which must write the full stack trace to a log or file, along with a timestamp using __logging__ module. Each logger object has a method called exception, taking a message string. If you call it in the except block, the caught exception will automatically be fully logged, including the trace."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-12T08:32:35.924133Z",
"start_time": "2018-11-12T08:32:35.916331Z"
},
"trusted": true
},
"cell_type": "code",
"source": "import logging\n\ndef get_number():\n return int('foo')\n\ntry:\n x = get_number()\n print(\"foo\")\nexcept Exception as ex:\n logging.exception('Error!')",
"execution_count": 23,
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": "ERROR:root:Error!\nTraceback (most recent call last):\n File \"<ipython-input-23-f77cb23c4c07>\", line 7, in <module>\n x = get_number()\n File \"<ipython-input-23-f77cb23c4c07>\", line 4, in get_number\n return int('foo')\nValueError: invalid literal for int() with base 10: 'foo'\n"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Q3 <a name=\"ans3\"></a>\n\nAn assertion would stop the program from running (because you should fix that error or the program is useless), but an exception would let the program continue running (if you use else or finally). In other words, __exceptions address the robustness of your application__ while __assertions address its correctness__. \n\nAssertions should be used to check something that __should never happen__ while an exception should be used to check something that __might happen__ (something in which you don't have control like user input). \n\n__NOTE__: The rule is that use __assertions__ when you are trying to __catch your own errors__ (functions or data that are internal to your system), and __exceptions__ when trying to __catch other people's errors__.\n\nUse assertions\n* when checking pre-conditions, post-conditions in code\n* to provide feedback to yourself or your developer team, making it a great feature for debugging purpose\n* when checking for things that are very unlikely to happen otherwise it means that there is a serious flaw in your application\n* to state things that you (supposedly) know to be true."
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.6",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "Python Notebook | Intermediate | Part 1.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment