|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## 1. Arithmetic\n", |
| 8 | + "Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc." |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "metadata": {}, |
| 14 | + "source": [ |
| 15 | + "<img src=\"../img/arithmetic.png\" alt=\"fishy\" class=\"bg-primary mb-1\">\n", |
| 16 | + "<h4><center>List of arithmetic operators in Python</center></h4>\n", |
| 17 | + "\n", |
| 18 | + "-----------" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 1, |
| 24 | + "metadata": {}, |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "x + y = 19\n", |
| 31 | + "x - y = 11\n", |
| 32 | + "x * y = 60\n", |
| 33 | + "x / y = 3.75\n", |
| 34 | + "x // y = 3\n", |
| 35 | + "x ** y = 50625\n" |
| 36 | + ] |
| 37 | + } |
| 38 | + ], |
| 39 | + "source": [ |
| 40 | + "x = 15\n", |
| 41 | + "y = 4\n", |
| 42 | + "\n", |
| 43 | + "# Output: x + y = 19\n", |
| 44 | + "print('x + y =',x+y)\n", |
| 45 | + "\n", |
| 46 | + "# Output: x - y = 11\n", |
| 47 | + "print('x - y =',x-y)\n", |
| 48 | + "\n", |
| 49 | + "# Output: x * y = 60\n", |
| 50 | + "print('x * y =',x*y)\n", |
| 51 | + "\n", |
| 52 | + "# Output: x / y = 3.75\n", |
| 53 | + "print('x / y =',x/y)\n", |
| 54 | + "\n", |
| 55 | + "# Output: x // y = 3\n", |
| 56 | + "print('x // y =',x//y)\n", |
| 57 | + "\n", |
| 58 | + "# Output: x ** y = 50625\n", |
| 59 | + "print('x ** y =',x**y)" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "markdown", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "------------" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "markdown", |
| 71 | + "metadata": {}, |
| 72 | + "source": [ |
| 73 | + "## 2. Comparison\n", |
| 74 | + "Comparison operators are used to compare values. It returns either True or False according to the condition." |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "markdown", |
| 79 | + "metadata": {}, |
| 80 | + "source": [ |
| 81 | + "<img src=\"../img/comparison.png\" alt=\"fishy\" class=\"bg-primary mb-1\">\n", |
| 82 | + "<h4><center>List of comparison operators in Python</center></h4>\n", |
| 83 | + "\n", |
| 84 | + "-----------" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": 2, |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [ |
| 92 | + { |
| 93 | + "name": "stdout", |
| 94 | + "output_type": "stream", |
| 95 | + "text": [ |
| 96 | + "x > y is False\n", |
| 97 | + "x < y is True\n", |
| 98 | + "x == y is False\n", |
| 99 | + "x != y is True\n", |
| 100 | + "x >= y is False\n", |
| 101 | + "x <= y is True\n" |
| 102 | + ] |
| 103 | + } |
| 104 | + ], |
| 105 | + "source": [ |
| 106 | + "x = 10\n", |
| 107 | + "y = 12\n", |
| 108 | + "\n", |
| 109 | + "# Output: x > y is False\n", |
| 110 | + "print('x > y is',x>y)\n", |
| 111 | + "\n", |
| 112 | + "# Output: x < y is True\n", |
| 113 | + "print('x < y is',x<y)\n", |
| 114 | + "\n", |
| 115 | + "# Output: x == y is False\n", |
| 116 | + "print('x == y is',x==y)\n", |
| 117 | + "\n", |
| 118 | + "# Output: x != y is True\n", |
| 119 | + "print('x != y is',x!=y)\n", |
| 120 | + "\n", |
| 121 | + "# Output: x >= y is False\n", |
| 122 | + "print('x >= y is',x>=y)\n", |
| 123 | + "\n", |
| 124 | + "# Output: x <= y is True\n", |
| 125 | + "print('x <= y is',x<=y)" |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "markdown", |
| 130 | + "metadata": {}, |
| 131 | + "source": [ |
| 132 | + "-------------" |
| 133 | + ] |
| 134 | + }, |
| 135 | + { |
| 136 | + "cell_type": "markdown", |
| 137 | + "metadata": {}, |
| 138 | + "source": [ |
| 139 | + "## 3. Logical\n", |
| 140 | + "Logical operators are the and, or, not operators." |
| 141 | + ] |
| 142 | + }, |
| 143 | + { |
| 144 | + "cell_type": "markdown", |
| 145 | + "metadata": {}, |
| 146 | + "source": [ |
| 147 | + "<img src=\"../img/logical.png\" alt=\"fishy\" class=\"bg-primary mb-1\">\n", |
| 148 | + "<h4><center>List of logical operators in Python</center></h4>\n", |
| 149 | + "\n", |
| 150 | + "-----------" |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + "cell_type": "code", |
| 155 | + "execution_count": 3, |
| 156 | + "metadata": {}, |
| 157 | + "outputs": [ |
| 158 | + { |
| 159 | + "name": "stdout", |
| 160 | + "output_type": "stream", |
| 161 | + "text": [ |
| 162 | + "x and y is False\n", |
| 163 | + "x or y is True\n", |
| 164 | + "not x is False\n" |
| 165 | + ] |
| 166 | + } |
| 167 | + ], |
| 168 | + "source": [ |
| 169 | + "x = True\n", |
| 170 | + "y = False\n", |
| 171 | + "\n", |
| 172 | + "print('x and y is',x and y)\n", |
| 173 | + "\n", |
| 174 | + "print('x or y is',x or y)\n", |
| 175 | + "\n", |
| 176 | + "print('not x is',not x)" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "markdown", |
| 181 | + "metadata": {}, |
| 182 | + "source": [ |
| 183 | + "---------" |
| 184 | + ] |
| 185 | + }, |
| 186 | + { |
| 187 | + "cell_type": "markdown", |
| 188 | + "metadata": {}, |
| 189 | + "source": [ |
| 190 | + "## 4. Assignment\n", |
| 191 | + "Assignment operators are used in Python to assign values to variables." |
| 192 | + ] |
| 193 | + }, |
| 194 | + { |
| 195 | + "cell_type": "markdown", |
| 196 | + "metadata": {}, |
| 197 | + "source": [ |
| 198 | + "`a = 5` is a simple assignment operator that assigns the value 5 on the right to the variable a on the left.\n", |
| 199 | + "\n", |
| 200 | + "There are various compound operators in Python like `a += 5` that adds to the variable and later assigns the same. It is equivalent to `a = a + 5`." |
| 201 | + ] |
| 202 | + }, |
| 203 | + { |
| 204 | + "cell_type": "markdown", |
| 205 | + "metadata": {}, |
| 206 | + "source": [ |
| 207 | + "<img src=\"../img/assignment.png\" alt=\"fishy\" class=\"bg-primary mb-1\">\n", |
| 208 | + "<h4><center>List of assignment operators in Python</center></h4>\n", |
| 209 | + "\n", |
| 210 | + "-----------" |
| 211 | + ] |
| 212 | + }, |
| 213 | + { |
| 214 | + "cell_type": "markdown", |
| 215 | + "metadata": {}, |
| 216 | + "source": [ |
| 217 | + "## 5. Identity\n", |
| 218 | + "`is` and `is not` are the identity operators in Python. They are used to check if two values (or variables) are located on the same part of the memory. Two variables that are equal does not imply that they are identical." |
| 219 | + ] |
| 220 | + }, |
| 221 | + { |
| 222 | + "cell_type": "markdown", |
| 223 | + "metadata": {}, |
| 224 | + "source": [ |
| 225 | + "<img src=\"../img/identity.png\" alt=\"fishy\" class=\"bg-primary mb-1\">\n", |
| 226 | + "<h4><center>List of identity operators in Python</center></h4>\n", |
| 227 | + "\n", |
| 228 | + "-----------" |
| 229 | + ] |
| 230 | + }, |
| 231 | + { |
| 232 | + "cell_type": "code", |
| 233 | + "execution_count": 5, |
| 234 | + "metadata": {}, |
| 235 | + "outputs": [ |
| 236 | + { |
| 237 | + "name": "stdout", |
| 238 | + "output_type": "stream", |
| 239 | + "text": [ |
| 240 | + "False\n", |
| 241 | + "True\n", |
| 242 | + "False\n" |
| 243 | + ] |
| 244 | + } |
| 245 | + ], |
| 246 | + "source": [ |
| 247 | + "x1 = 5\n", |
| 248 | + "y1 = 5\n", |
| 249 | + "x2 = 'Hello'\n", |
| 250 | + "y2 = 'Hello'\n", |
| 251 | + "x3 = [1,2,3]\n", |
| 252 | + "y3 = [1,2,3]\n", |
| 253 | + "\n", |
| 254 | + "# Output: False\n", |
| 255 | + "print(x1 is not y1)\n", |
| 256 | + "\n", |
| 257 | + "# Output: True\n", |
| 258 | + "print(x2 is y2)\n", |
| 259 | + "\n", |
| 260 | + "# Output: False\n", |
| 261 | + "print(x3 is y3)" |
| 262 | + ] |
| 263 | + }, |
| 264 | + { |
| 265 | + "cell_type": "markdown", |
| 266 | + "metadata": {}, |
| 267 | + "source": [ |
| 268 | + "## 6. Membership\n", |
| 269 | + "`in` and `not in` are the membership operators in Python. They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary)." |
| 270 | + ] |
| 271 | + }, |
| 272 | + { |
| 273 | + "cell_type": "markdown", |
| 274 | + "metadata": {}, |
| 275 | + "source": [ |
| 276 | + "<img src=\"../img/membership.png\" alt=\"fishy\" class=\"bg-primary mb-1\">\n", |
| 277 | + "<h4><center>List of membership operators in Python</center></h4>\n", |
| 278 | + "\n", |
| 279 | + "-----------" |
| 280 | + ] |
| 281 | + }, |
| 282 | + { |
| 283 | + "cell_type": "code", |
| 284 | + "execution_count": 6, |
| 285 | + "metadata": {}, |
| 286 | + "outputs": [ |
| 287 | + { |
| 288 | + "name": "stdout", |
| 289 | + "output_type": "stream", |
| 290 | + "text": [ |
| 291 | + "True\n", |
| 292 | + "True\n", |
| 293 | + "True\n", |
| 294 | + "False\n" |
| 295 | + ] |
| 296 | + } |
| 297 | + ], |
| 298 | + "source": [ |
| 299 | + "x = 'Hello world'\n", |
| 300 | + "y = {1:'a',2:'b'}\n", |
| 301 | + "\n", |
| 302 | + "# Output: True\n", |
| 303 | + "print('H' in x)\n", |
| 304 | + "\n", |
| 305 | + "# Output: True\n", |
| 306 | + "print('hello' not in x)\n", |
| 307 | + "\n", |
| 308 | + "# Output: True\n", |
| 309 | + "print(1 in y)\n", |
| 310 | + "\n", |
| 311 | + "# Output: False\n", |
| 312 | + "print('a' in y)" |
| 313 | + ] |
| 314 | + }, |
| 315 | + { |
| 316 | + "cell_type": "code", |
| 317 | + "execution_count": null, |
| 318 | + "metadata": {}, |
| 319 | + "outputs": [], |
| 320 | + "source": [] |
| 321 | + } |
| 322 | + ], |
| 323 | + "metadata": { |
| 324 | + "kernelspec": { |
| 325 | + "display_name": "Python 3", |
| 326 | + "language": "python", |
| 327 | + "name": "python3" |
| 328 | + }, |
| 329 | + "language_info": { |
| 330 | + "codemirror_mode": { |
| 331 | + "name": "ipython", |
| 332 | + "version": 3 |
| 333 | + }, |
| 334 | + "file_extension": ".py", |
| 335 | + "mimetype": "text/x-python", |
| 336 | + "name": "python", |
| 337 | + "nbconvert_exporter": "python", |
| 338 | + "pygments_lexer": "ipython3", |
| 339 | + "version": "3.8.5" |
| 340 | + } |
| 341 | + }, |
| 342 | + "nbformat": 4, |
| 343 | + "nbformat_minor": 4 |
| 344 | +} |
0 commit comments