{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# **A Simple Python Cheat Sheet**\n\nnote : I'm sorry if there are mistakes in words and meaning, hopefully you guys can understand it, thanks in advance !!!","metadata":{}},{"cell_type":"markdown","source":"# **Table Of Contents**\n\n* Main Python Data Types\n* Built-in Function in Python\n* Math Operator\n* List\n* Tuples\n* Dictionaries\n* Define a Function\n* If statements in Python\n* Python Loops\n* Class\n* Dealing with Python Excpetions (Errors)","metadata":{}},{"cell_type":"markdown","source":"# **Main Python Data Types**\n\nEvery value in python is called an **object**. And every object has a spesific data type. The three most-used data types are as follows:\n\n### **1. Integers (int)**\n\nIn Python, integers are zero, positive or negative whole numbers without a fractional part and having unlimited precision, e.g. 0, 100, -10. The followings are valid integer literals in Python. Integers can be binary, octal, and hexadecimal values. All integer literals or variables are objects of the int class.\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"# Zero, Negative, and Positive\nnumber_1, number_2, number_3 = 0, -2, 50\n\n# Binary, Octal, and Hexadesimal\nnumber_4, number_5, number_6 = 0b11011000, 0o12, 0x12\n\nprint(type(number_1), type(number_2), type(number_3))\nprint(type(number_4), type(number_5), type(number_6))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:53:43.196702Z","iopub.execute_input":"2022-02-23T08:53:43.197543Z","iopub.status.idle":"2022-02-23T08:53:43.216462Z","shell.execute_reply.started":"2022-02-23T08:53:43.197444Z","shell.execute_reply":"2022-02-23T08:53:43.214976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **2. Floating-point numbers (float)**\n\nIn Python, floating point numbers (float) are positive and negative real numbers with a fractional part denoted by the decimal symbol . or the scientific notation E or e, e.g. 1234.56, 3.142, -1.55, 0.23.\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"# Float 1, 2, 3\nnumber_1, number_2, number_3 = 0.0, -2.0, 50.87\n\n# Float with many number, Float with underscore, and Scientific notation\nnumber_4, number_5, number_6 = 123.123, 123_123.3221, 1e5\n\nprint(type(number_1), type(number_2), type(number_3))\nprint(type(number_4), type(number_5), type(number_6))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:53:43.239170Z","iopub.execute_input":"2022-02-23T08:53:43.239830Z","iopub.status.idle":"2022-02-23T08:53:43.248392Z","shell.execute_reply.started":"2022-02-23T08:53:43.239788Z","shell.execute_reply":"2022-02-23T08:53:43.247311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **3. Strings (str)**\n\nIn Python, string is an immutable sequence data type. It is the sequence of Unicode characters wrapped inside single, double, or triple quotes.\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"str_1='This is a string in Python' # With single quote\nstr_2=\"This is a string in Python\" # With double quote\n\n# Multiline String with single quote\nstr_3='''This is  \nthe first\nMulti-line string.\n''' \n\n# Multiline String with double quote\nstr_4=\"\"\"This is\nthe second\nMulti-line\nstring.\"\"\"\n\nprint(type(str_1), type(str_2))\nprint(type(str_3), type(str_4))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:53:43.266007Z","iopub.execute_input":"2022-02-23T08:53:43.266663Z","iopub.status.idle":"2022-02-23T08:53:43.275122Z","shell.execute_reply.started":"2022-02-23T08:53:43.266625Z","shell.execute_reply":"2022-02-23T08:53:43.273863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Built-in functions in Python\n\nThe Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order. You already know the most popular function in Python, yap you're right, is a **print()** function. Now let's take a look at its equally popular cousins that are in-built in the platform, I'll not showing you guys all of this built in function, if you want to know more, I'll give you the link below.\n\nHere's the link : https://docs.python.org/3/library/functions.html\n\n### **1. input() Function**\n\nAllows user to input values.\n\n#### **Example :** ","metadata":{}},{"cell_type":"code","source":"name = input(\"Hi!, what's your name? \")\nprint(\"Nice to meet you \" + name + \"!\")\n\nage = input(\"How old are you? \")\nprint(\"So you already \" + str(age) + \"years old, that's nice!\")","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:53:43.301402Z","iopub.execute_input":"2022-02-23T08:53:43.302006Z","iopub.status.idle":"2022-02-23T08:54:04.528014Z","shell.execute_reply.started":"2022-02-23T08:53:43.301970Z","shell.execute_reply":"2022-02-23T08:54:04.527130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **2. len() Function**\n\nReturns the length of the object. Returns total elements in an iterable or number of chars in a string.\n\n#### **Example :** ","metadata":{}},{"cell_type":"code","source":"len_1 = \"Hope you are enjoying mu Cheat-Sheet!\"\nprint(\"The length of the string is :\", len(len_1))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.529489Z","iopub.execute_input":"2022-02-23T08:54:04.529982Z","iopub.status.idle":"2022-02-23T08:54:04.535915Z","shell.execute_reply.started":"2022-02-23T08:54:04.529948Z","shell.execute_reply":"2022-02-23T08:54:04.535062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **3. max() and min() Function**\n\n- max() : Returns the largest value from the specified iterable or multiple arguments.\n- min() : Returns the lowest value from the specified iterable or provided multiple arguments.\n\n#### **Example :** ","metadata":{}},{"cell_type":"code","source":"my_max_num = [5, 10, 40]\nprint(f\"My max num is: {max(my_max_num)}\")\n\nmy_min_num = [5, 10, 40]\nprint(f\"My min num is: {min(my_max_num)}\")","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.538220Z","iopub.execute_input":"2022-02-23T08:54:04.538661Z","iopub.status.idle":"2022-02-23T08:54:04.553114Z","shell.execute_reply.started":"2022-02-23T08:54:04.538617Z","shell.execute_reply":"2022-02-23T08:54:04.552086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Math Operator**\n\nArithmetic operators are used to perform mathematical operations like **addition**, **subtraction**, **multiplication** and **division**.\n\nThere are **7 arithmetic operators in Python** :\n\n1. **Addition**\n2. **Subtraction**\n3. **Multiplication**\n4. **Division**\n5. **Modulus**\n6. **Exponentiation**\n7. **Floor division**\n\n- **Addition Operator** : In Python, + is the addition operator. It is used to add 2 values or more.\n- **Subtraction Operator** : In Python, - is the subtraction operator. It is used to subtract 2 values or more.\n- **Multiplication Operator** : In python, to multiply number, we will use the asterisk character ” * ” to multiply number.\n- **Division Operator** : Divides the number on its left by the number on its right and returns a floating point value.\n- **Modulus Operator** : The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand.\n- **Exponentation Operator** : One important basic arithmetic operator, in Python, is the exponent operator. It takes in two real numbers as input arguments and returns a single number. The operator that can be used to perform the exponent arithmetic in Python is ** .\n- **Floor Division Operator** : Divides the number on its left by the number on its right, rounds down the answer, and returns a whole number.\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"# (**) = Exponent\nprint('Exponent')\nprint(2 ** 4)\n\n# (%) = Modulus/Remainder\nprint('Modulus/Remainder')\nprint(25 % 3)\n\n# (//) = Floor Division\nprint('Floor Division')\nprint(25 // 3)\n\n# (/) = Division\nprint('Division')\nprint(25 / 3)\n\n# (*) = Multiplication\nprint('Multiplication')\nprint(4 * 9)\n\n# (-) = Subtraction\nprint('Subtraction')\nprint(5 - 4)\n\n# (+) = Addition\nprint('Addition')\nprint(9 + 4)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.554934Z","iopub.execute_input":"2022-02-23T08:54:04.555530Z","iopub.status.idle":"2022-02-23T08:54:04.568380Z","shell.execute_reply.started":"2022-02-23T08:54:04.555497Z","shell.execute_reply":"2022-02-23T08:54:04.567371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **List**\n\nA **list** is an ordered and mutable Python container, being one of the most common data structures in Python. To create a **list**, the elements are placed inside square brackets **([])**, separated by commas. As shown above, **lists** can contain elements of different types as well as duplicated elements.\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"my_list = [1, 2, 3]\nmy_list2 = ['a', \"b\", 'c']\nmy_list3 = ['a', 1, True, 0.5]\n\nprint(my_list)\nprint(my_list2)\nprint(my_list3)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.569440Z","iopub.execute_input":"2022-02-23T08:54:04.569869Z","iopub.status.idle":"2022-02-23T08:54:04.580271Z","shell.execute_reply.started":"2022-02-23T08:54:04.569836Z","shell.execute_reply":"2022-02-23T08:54:04.579273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* Use **append()** function if you want to add a new items to list.\n* Use **remove()** function if you want to remove an items on a list.\n* Or you can use **pop()** function, it will remove the last item, if, no index specified.\n\nFor more information about list, you can check this python site : https://docs.python.org/3/tutorial/datastructures.html","metadata":{}},{"cell_type":"markdown","source":"# **Tuple**\n\nPython **tuples** are a data structure that store an ordered sequence of values. **Tuples are immutable**. This means you cannot change the values in a **tuple**. Tuples are similar to lists, they allow you to display an ordered sequence of elements. The advantage of using tuples over lists is that the former are slightly faster. So it's a nice way to optimize your code.\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"my_tuple = (1, 2, 3, 4, 5)\nmy_tuple[0:3] # You can slice a tuple","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.581546Z","iopub.execute_input":"2022-02-23T08:54:04.581848Z","iopub.status.idle":"2022-02-23T08:54:04.595974Z","shell.execute_reply.started":"2022-02-23T08:54:04.581814Z","shell.execute_reply":"2022-02-23T08:54:04.595140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **How to Slide a Tuple**\n#### The process is similar to slicing lists.","metadata":{}},{"cell_type":"code","source":"numbers = (0, 1, 3, 4, 5, 6, 1, 4, 2, 4, 5, 6, 8, 1)\nprint(numbers[1:11:2])","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.597212Z","iopub.execute_input":"2022-02-23T08:54:04.597693Z","iopub.status.idle":"2022-02-23T08:54:04.608133Z","shell.execute_reply.started":"2022-02-23T08:54:04.597663Z","shell.execute_reply":"2022-02-23T08:54:04.607097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For more infomation about how to use Tuple, here's the link : https://docs.python.org/3/tutorial/datastructures.html","metadata":{}},{"cell_type":"markdown","source":"# **Dictionary**\n\n**Dictionary** in Python is an unordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, **Dictionary** holds **key:value** pair. **Key-value** is provided in the **dictionary** to make it more optimized.\n\n#### **Example :** ","metadata":{}},{"cell_type":"code","source":"new_dict = {\n    'Name': 'Knightbearr',\n    'Age': 18,\n    'Hobbies': 'Read Books' # Actually nah XD\n}\n\nprint(new_dict)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.700055Z","iopub.execute_input":"2022-02-23T08:54:04.700397Z","iopub.status.idle":"2022-02-23T08:54:04.705568Z","shell.execute_reply.started":"2022-02-23T08:54:04.700369Z","shell.execute_reply":"2022-02-23T08:54:04.704708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **How to Acces a Value in Dictionary**\n\n#### You can acces any of the values in your dictionary the following way :","metadata":{}},{"cell_type":"code","source":"x = new_dict['Name']","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.707295Z","iopub.execute_input":"2022-02-23T08:54:04.707680Z","iopub.status.idle":"2022-02-23T08:54:04.718379Z","shell.execute_reply.started":"2022-02-23T08:54:04.707649Z","shell.execute_reply":"2022-02-23T08:54:04.717357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### **You can also use the following methods to accomplish the same.**\n* **dict.keys()** isolates keys\n* **dict.values()** isolates values\n* **dict.items()** returns items in a list format of (key, value) yuple pairs\n\n### **Change item Value**\n\n#### To change one of the items, you need to refer to by its key name:","metadata":{}},{"cell_type":"code","source":"# Change the \"Hobbies\" to Jogging\n\nnew_dict = {\n    'Name': 'Knightbearr',\n    'Age': 18,\n    'Hobbies': 'Read Books' # Actually nah XD\n}\n\nnew_dict['Hobbies'] = 'Jogging'\n\nprint(new_dict)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.719455Z","iopub.execute_input":"2022-02-23T08:54:04.719916Z","iopub.status.idle":"2022-02-23T08:54:04.733952Z","shell.execute_reply.started":"2022-02-23T08:54:04.719884Z","shell.execute_reply":"2022-02-23T08:54:04.732987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For more infomation about how to use Dictionary, here's the link : https://docs.python.org/3/tutorial/datastructures.html","metadata":{}},{"cell_type":"markdown","source":"# **Define a Function**\n\nA Python **function** is a group of code. To run the code in a **function**, you must call the **function**. **Functions** can return a value using a return statement. **Functions** are a common feature among all programming languages. They allow developers to write blocks of code that perform specific tasks.\n\n#### **Example :** ","metadata":{}},{"cell_type":"code","source":"def name(): \n    pass # pass is a null statement, nothing happens and the statement results into no operation.","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.735294Z","iopub.execute_input":"2022-02-23T08:54:04.735685Z","iopub.status.idle":"2022-02-23T08:54:04.744409Z","shell.execute_reply.started":"2022-02-23T08:54:04.735645Z","shell.execute_reply":"2022-02-23T08:54:04.743442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def name():\n    print(\"What's your name?\") # Now you can call/invoke the function\n    \nname()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.745617Z","iopub.execute_input":"2022-02-23T08:54:04.745959Z","iopub.status.idle":"2022-02-23T08:54:04.757322Z","shell.execute_reply.started":"2022-02-23T08:54:04.745916Z","shell.execute_reply":"2022-02-23T08:54:04.756354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Now, let's take a look at a defined function with a parameter.\n\nLet's make function to calculate the perimeter and area of a square.","metadata":{}},{"cell_type":"code","source":"def square(width, length):\n    around = 2 * (width + length)\n    large = (width * length)\n    return around, large\n\n\naround_result, large_result = square(10, 20)\nprint(f'Around result: {around_result}, Large result: {large_result}')","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.758596Z","iopub.execute_input":"2022-02-23T08:54:04.759184Z","iopub.status.idle":"2022-02-23T08:54:04.770533Z","shell.execute_reply.started":"2022-02-23T08:54:04.759141Z","shell.execute_reply":"2022-02-23T08:54:04.769867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For more information about Python Function, here's the link : https://www.w3schools.com/python/python_functions.asp","metadata":{}},{"cell_type":"markdown","source":"# **If Statements In Python**\n\nConditional Statement in Python perform different computations or actions depending on whether a specific Boolean constraint evaluates to true or false. Conditional statements are handled by IF statements in Python.\n\nJust like other programming languages, Python support the basic logical conditions from math:\n\n* **Equals**: a **==** b\n* **Not Equals:** a **!=** b\n* **Less than:** a **<** b\n* **Less than or equal to:** a **<=** b\n* **Greater than:** a **>** b\n* **Greater than or equal to:** a **>=** b\n\nYou can leverage these conditions in various ways. But most likely, you'll use them in **\"if statements\"** and **loops**\n\n#### **Example :**","metadata":{}},{"cell_type":"code","source":"# The goal of conditional statements is to check if it's True or False.\nif 100 > 1:\n    print(\"That's true\")","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.771546Z","iopub.execute_input":"2022-02-23T08:54:04.771880Z","iopub.status.idle":"2022-02-23T08:54:04.783005Z","shell.execute_reply.started":"2022-02-23T08:54:04.771851Z","shell.execute_reply":"2022-02-23T08:54:04.782002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Nested If Statements**","metadata":{}},{"cell_type":"code","source":"x = 40\n\nif x > 20:\n    print('Above twenty')\n    if x > 30:\n        print('Also above 30!')","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.784466Z","iopub.execute_input":"2022-02-23T08:54:04.785010Z","iopub.status.idle":"2022-02-23T08:54:04.796739Z","shell.execute_reply.started":"2022-02-23T08:54:04.784973Z","shell.execute_reply":"2022-02-23T08:54:04.795557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For more informations about If statements, here's the link : https://www.w3schools.com/python/python_conditions.asp","metadata":{}},{"cell_type":"markdown","source":"# **Python Loops**\n\nPython has two simple loop commands that are good to know:\n\n* For loops\n* While loops\n\nLet's take a look at each of these.\n\n### **1. For Loops**\n\nFor-loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly. Various keywords are used to specify this statement: descendants of ALGOL use \"for\", while descendants of Fortran use \"do\".","metadata":{}},{"cell_type":"code","source":"for i in 'nikola tesla':\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.798187Z","iopub.execute_input":"2022-02-23T08:54:04.798624Z","iopub.status.idle":"2022-02-23T08:54:04.812144Z","shell.execute_reply.started":"2022-02-23T08:54:04.798581Z","shell.execute_reply":"2022-02-23T08:54:04.811320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **2. While loops**\n\nPython while Loop Statements, A while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is True.","metadata":{}},{"cell_type":"code","source":"i = 0\n\nwhile i < 5:\n    print(i)\n    i += 1","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.813129Z","iopub.execute_input":"2022-02-23T08:54:04.813518Z","iopub.status.idle":"2022-02-23T08:54:04.825387Z","shell.execute_reply.started":"2022-02-23T08:54:04.813488Z","shell.execute_reply":"2022-02-23T08:54:04.824560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### **How to break a loop**","metadata":{}},{"cell_type":"code","source":"i = 0\n\nwhile i < 5:\n    if i == 3:\n        break\n    print(i)\n    i += 1","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.826672Z","iopub.execute_input":"2022-02-23T08:54:04.827165Z","iopub.status.idle":"2022-02-23T08:54:04.836988Z","shell.execute_reply.started":"2022-02-23T08:54:04.827128Z","shell.execute_reply":"2022-02-23T08:54:04.835935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For more information about Python loops, here's the link: \n\n* While Loops : https://www.w3schools.com/python/python_while_loops.asp\n* For Loops : https://www.w3schools.com/python/python_for_loops.asp","metadata":{}},{"cell_type":"markdown","source":"# **Class**\n\nA Python class is like an outline for creating a new object. An object is anything that you wish to manipulate or change while working through the code. Every time a class object is instantiated, which is when we declare a variable, a new object is initiated from scratch.\n\n### **Example :** ","metadata":{}},{"cell_type":"markdown","source":"#### **How to Create a Class**\n\nLet's create a class named superClass, with one property named s","metadata":{}},{"cell_type":"code","source":"class superClass:\n    s = 100","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.838187Z","iopub.execute_input":"2022-02-23T08:54:04.838466Z","iopub.status.idle":"2022-02-23T08:54:04.848626Z","shell.execute_reply.started":"2022-02-23T08:54:04.838439Z","shell.execute_reply":"2022-02-23T08:54:04.847571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### **How to Create an Object**\n\nAs a next step, you can create an object using your class, Here's how it's done:","metadata":{}},{"cell_type":"code","source":"c1 = superClass()\nprint(c1.s)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.850054Z","iopub.execute_input":"2022-02-23T08:54:04.850376Z","iopub.status.idle":"2022-02-23T08:54:04.862107Z","shell.execute_reply.started":"2022-02-23T08:54:04.850347Z","shell.execute_reply":"2022-02-23T08:54:04.861045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Further you can assign different attributes and methods to your object. The example below:","metadata":{}},{"cell_type":"code","source":"# Class and Object 1\nclass Car:\n    carCount = 0\n    def __init__(self, name, color):\n        self.name = name\n        self.color = color\n        Car.carCount += 1\n    def getCar(self):\n        return \"Name : \" + self.name + \", Color : \"  + self.color\n\nford1 = Car(\"Ford\", \"Red\")\ntoyota1 = Car(\"Toyota\", \"Green\")\nprint(f\"Total of Car : {Car.carCount}\")\nprint(\"Car 1 : \\n\" + ford1.getCar())\nprint(\"Car 2 : \\n\" + toyota1.getCar())\n\n# Class and Object 2\nclass Person:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n    def getIdentitas(self):\n        return \"Name : \" + self.name + \", age : \" + str(self.age)\n\nazmi = Person('Azmi', 18)\nfujimoto = Person('Fujimoto', 20)\nprint(azmi.getIdentitas())\nprint(fujimoto.getIdentitas())","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.863452Z","iopub.execute_input":"2022-02-23T08:54:04.864062Z","iopub.status.idle":"2022-02-23T08:54:04.877564Z","shell.execute_reply.started":"2022-02-23T08:54:04.864017Z","shell.execute_reply":"2022-02-23T08:54:04.876490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Fo more information about the Python Class, here's the link: https://docs.python.org/3/tutorial/classes.html","metadata":{}},{"cell_type":"markdown","source":"# **Dealing with Python Exceptions (Error)**\n\nUntil now error messages haven’t been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds of errors: syntax errors and exceptions.\n\n### **The Most Common Python Exceptions:**\n\n* **AssertionError** = Raised when the assert statement fails.\n* **AttributeError** = Raised on the attribute assignment or reference fails.\n* **EOFError** = Raised when the input() function hits the end-of-file condition.\n* **FloatingPointError** = Raised when a floating point operation fails.\n* **ImportError** = Raised when the imported module is not found.\n* **IndexError** = Raised when the index of a sequence is out of range.\n* **KeyError** = Raised when a key is not found in a dictionary.\n* **KeyboardInterrupt** = Raised when the user hits the interrupt key (Ctrl+c or delete).\n* **MemoryError** = Raised when an operation runs out of memory.\n* **NameError** = Raised when a variable is not found in the local or global scope.\n* **RuntimeError** = Raised when an error does not fall under any other category.\n* **StopIteration** = Raised by the next() function to indicate that there is no further item to be returned by the iterator.\n* **SyntaxError** = Raised by the parser when a syntax error is encountered.\n* **IndentationError** = Raised when there is an incorrect indentation.\n* **TabError** = Raised when the indentation consists of inconsistent tabs and spaces.\n* **TypeError** = Raised when a function or operation is applied to an object of an incorrect type.\n* **UnboundLocalError** = Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable.\n* **UnicodeError** = Raised when a Unicode-related encoding or decoding error occurs.\n* **ValueError** = Raised when a function gets an argument of correct type but improper value.\n* **ZeroDivisionError** = Raised when the second operand of a division or module operation is zero.\n\nIf you want to know more about Error in Python, here's the link : \n\n* https://www.tutorialsteacher.com/python/error-types-in-python\n* https://docs.python.org/3/tutorial/errors.html","metadata":{}},{"cell_type":"markdown","source":"### **How to Troubleshot the Errors**\n\nPython has a useful statement, design just for the purpose of handling exceptions, **try/except** statement, Here's the code showing you can catch KeyErrors in dictionary using this statement:","metadata":{}},{"cell_type":"markdown","source":"### **1. Key Error Example**","metadata":{}},{"cell_type":"code","source":"my_dict = {'a':1, 'b':2, 'c':3}\n\ntry:\n    value = my_dict['d']\nexcept KeyError:\n    print(\"That key doesn't exist!\")","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.880897Z","iopub.execute_input":"2022-02-23T08:54:04.881456Z","iopub.status.idle":"2022-02-23T08:54:04.894345Z","shell.execute_reply.started":"2022-02-23T08:54:04.881421Z","shell.execute_reply":"2022-02-23T08:54:04.892505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **2. Value Error and Zero Division Error**","metadata":{}},{"cell_type":"code","source":"print(\"Division\")\n\nwhile True:\n    try:\n        denominator = int(input(\"Input the denominator: \"))\n        numerator = int(input(\"Input the numerator: \"))\n        result = denominator/numerator\n        break\n    except ValueError:\n        print(\"Is not a number\")\n    except ZeroDivisionError:\n        print(\"The Numerator is Zero, Please choose another number ^-^\")","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:54:04.897287Z","iopub.execute_input":"2022-02-23T08:54:04.897808Z","iopub.status.idle":"2022-02-23T08:54:15.157370Z","shell.execute_reply.started":"2022-02-23T08:54:04.897770Z","shell.execute_reply":"2022-02-23T08:54:15.155272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Conclusions**\n\n# Now you know the basics and core python quickly!\n\n## I hope this cheat sheet is useful for you guys, don't forget to give a Feedback and Upvote if you like it !!!\n\n## Thanks in advance !!!\n\n> @knightbearr","metadata":{}}]}