├── README.md ├── example.ipynb └── python101.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # Python101 2 | Python101 examples 3 | -------------------------------------------------------------------------------- /example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "example.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [], 9 | "authorship_tag": "ABX9TyPUc8gUbyVyDdQWwbR+o56P", 10 | "include_colab_link": true 11 | }, 12 | "kernelspec": { 13 | "name": "python3", 14 | "display_name": "Python 3" 15 | }, 16 | "language_info": { 17 | "name": "python" 18 | } 19 | }, 20 | "cells": [ 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "id": "view-in-github", 25 | "colab_type": "text" 26 | }, 27 | "source": [ 28 | "\"Open" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 16, 34 | "metadata": { 35 | "id": "Sb0HvGKBcYtY" 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "basket = []" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "source": [ 45 | "def check_item(item):\n", 46 | " keys = item.keys()\n", 47 | " values = item.values()\n", 48 | " if \"username\" not in keys or \"price\" not in keys or \"city\" not in keys or \"name\" not in keys:\n", 49 | " raise Exception(\"Please put name, username and price and city information to your item!\")\n", 50 | " for value in values:\n", 51 | " if value == None:\n", 52 | " raise Exception(f\"Some value is none, please check your item. {item}\")\n", 53 | " return True" 54 | ], 55 | "metadata": { 56 | "id": "Wz6q-cYGcuzB" 57 | }, 58 | "execution_count": 54, 59 | "outputs": [] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "source": [ 64 | "def create_item(username=None, price=None, city=None, name=None):\n", 65 | " return {\n", 66 | " \"username\": username,\n", 67 | " \"name\": name,\n", 68 | " \"price\": price,\n", 69 | " \"city\": city\n", 70 | " }" 71 | ], 72 | "metadata": { 73 | "id": "6keXnSgBdK55" 74 | }, 75 | "execution_count": 22, 76 | "outputs": [] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "source": [ 81 | "phone = create_item(username=\"kaan\", price=50, city=\"Aydin\", name=\"phone\")" 82 | ], 83 | "metadata": { 84 | "id": "953xmqdzdMYz" 85 | }, 86 | "execution_count": 24, 87 | "outputs": [] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "source": [ 92 | "phone" 93 | ], 94 | "metadata": { 95 | "colab": { 96 | "base_uri": "https://localhost:8080/" 97 | }, 98 | "id": "yXrVEUuKdpXe", 99 | "outputId": "bd4c7136-98c4-46d5-c9b9-7060cf4decf6" 100 | }, 101 | "execution_count": 25, 102 | "outputs": [ 103 | { 104 | "output_type": "execute_result", 105 | "data": { 106 | "text/plain": [ 107 | "{'city': 'Aydin', 'name': 'phone', 'price': 50, 'username': 'kaan'}" 108 | ] 109 | }, 110 | "metadata": {}, 111 | "execution_count": 25 112 | } 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "source": [ 118 | "def add_to_cart(item):\n", 119 | " is_proper = check_item(item)\n", 120 | " print(f\"check item returned {is_proper}\")\n", 121 | " if is_proper:\n", 122 | " basket.append(item)\n", 123 | " print(f\"{item['name']} added to basket\")\n", 124 | " else:\n", 125 | " raise Exception(\"Item is not proper\")" 126 | ], 127 | "metadata": { 128 | "id": "W9hOLVo6d56b" 129 | }, 130 | "execution_count": 44, 131 | "outputs": [] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "source": [ 136 | "add_to_cart(phone)" 137 | ], 138 | "metadata": { 139 | "colab": { 140 | "base_uri": "https://localhost:8080/" 141 | }, 142 | "id": "nCxfkf5keH7N", 143 | "outputId": "75a278a9-ae43-4c83-9d0c-9a1bd1e2d6a7" 144 | }, 145 | "execution_count": 33, 146 | "outputs": [ 147 | { 148 | "output_type": "stream", 149 | "name": "stdout", 150 | "text": [ 151 | "True\n" 152 | ] 153 | } 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "source": [ 159 | "watch = create_item(username=\"kaan\", price=50, name=\"watch\")" 160 | ], 161 | "metadata": { 162 | "id": "KOzDCwHyeK2P" 163 | }, 164 | "execution_count": 27, 165 | "outputs": [] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "source": [ 170 | "watch" 171 | ], 172 | "metadata": { 173 | "colab": { 174 | "base_uri": "https://localhost:8080/" 175 | }, 176 | "id": "olVKHq5qeV7e", 177 | "outputId": "4d0b258c-be43-4629-cb01-b6ce3360f851" 178 | }, 179 | "execution_count": 34, 180 | "outputs": [ 181 | { 182 | "output_type": "execute_result", 183 | "data": { 184 | "text/plain": [ 185 | "{'city': None, 'name': 'watch', 'price': 50, 'username': 'kaan'}" 186 | ] 187 | }, 188 | "metadata": {}, 189 | "execution_count": 34 190 | } 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "source": [ 196 | "basket" 197 | ], 198 | "metadata": { 199 | "colab": { 200 | "base_uri": "https://localhost:8080/" 201 | }, 202 | "id": "oNH3CyYJe9WG", 203 | "outputId": "a3a42c91-c6bd-45e2-d9ca-083160b87e86" 204 | }, 205 | "execution_count": 36, 206 | "outputs": [ 207 | { 208 | "output_type": "execute_result", 209 | "data": { 210 | "text/plain": [ 211 | "[{'city': 'Aydin', 'name': 'phone', 'price': 50, 'username': 'kaan'}]" 212 | ] 213 | }, 214 | "metadata": {}, 215 | "execution_count": 36 216 | } 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "source": [ 222 | "def get_basket():\n", 223 | " print(basket)" 224 | ], 225 | "metadata": { 226 | "id": "DkAuhcDyg-8K" 227 | }, 228 | "execution_count": 37, 229 | "outputs": [] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "source": [ 234 | "get_basket()" 235 | ], 236 | "metadata": { 237 | "colab": { 238 | "base_uri": "https://localhost:8080/" 239 | }, 240 | "id": "eO1B3zQihCLI", 241 | "outputId": "59002a27-adaf-41da-a10a-a9afffdd69fb" 242 | }, 243 | "execution_count": 38, 244 | "outputs": [ 245 | { 246 | "output_type": "stream", 247 | "name": "stdout", 248 | "text": [ 249 | "[{'username': 'kaan', 'name': 'phone', 'price': 50, 'city': 'Aydin'}]\n" 250 | ] 251 | } 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "source": [ 257 | "computer = create_item(username=\"batu\", price=150, name=\"computer\", city=\"Istanbul\")" 258 | ], 259 | "metadata": { 260 | "id": "euWNYJUvhDRb" 261 | }, 262 | "execution_count": 39, 263 | "outputs": [] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "source": [ 268 | "add_to_cart(computer)" 269 | ], 270 | "metadata": { 271 | "colab": { 272 | "base_uri": "https://localhost:8080/" 273 | }, 274 | "id": "u5BOCqKDhMgU", 275 | "outputId": "e4707de4-be16-44ff-e05c-368d201e91f0" 276 | }, 277 | "execution_count": 45, 278 | "outputs": [ 279 | { 280 | "output_type": "stream", 281 | "name": "stdout", 282 | "text": [ 283 | "check item returned True\n", 284 | "computer added to basket\n" 285 | ] 286 | } 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "source": [ 292 | "get_basket()" 293 | ], 294 | "metadata": { 295 | "colab": { 296 | "base_uri": "https://localhost:8080/" 297 | }, 298 | "id": "pfHpoiR6hOTp", 299 | "outputId": "7c20a00e-5db6-4971-9ac3-7f531aa478ea" 300 | }, 301 | "execution_count": 47, 302 | "outputs": [ 303 | { 304 | "output_type": "stream", 305 | "name": "stdout", 306 | "text": [ 307 | "[{'username': 'kaan', 'name': 'phone', 'price': 50, 'city': 'Aydin'}, {'username': 'batu', 'name': 'computer', 'price': 150, 'city': 'Istanbul'}, {'username': 'batu', 'name': 'computer', 'price': 150, 'city': 'Istanbul'}]\n" 308 | ] 309 | } 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "source": [ 315 | "def pop_last_item_from_basket():\n", 316 | " last_item = basket.pop()\n", 317 | " print(f\"Pop {last_item} is success!\")" 318 | ], 319 | "metadata": { 320 | "id": "MFirUoWXhj1H" 321 | }, 322 | "execution_count": 48, 323 | "outputs": [] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "source": [ 328 | "pop_last_item_from_basket()" 329 | ], 330 | "metadata": { 331 | "colab": { 332 | "base_uri": "https://localhost:8080/" 333 | }, 334 | "id": "wlEXikbLia0L", 335 | "outputId": "f44a9b5b-19bc-4c0b-ffad-df42da392e32" 336 | }, 337 | "execution_count": 49, 338 | "outputs": [ 339 | { 340 | "output_type": "stream", 341 | "name": "stdout", 342 | "text": [ 343 | "Pop {'username': 'batu', 'name': 'computer', 'price': 150, 'city': 'Istanbul'} is success!\n" 344 | ] 345 | } 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "source": [ 351 | "basket" 352 | ], 353 | "metadata": { 354 | "colab": { 355 | "base_uri": "https://localhost:8080/" 356 | }, 357 | "id": "nTZMUi7HicCd", 358 | "outputId": "bbd8d895-dfa8-4863-9dfe-baa3c9a1f66f" 359 | }, 360 | "execution_count": 50, 361 | "outputs": [ 362 | { 363 | "output_type": "execute_result", 364 | "data": { 365 | "text/plain": [ 366 | "[{'city': 'Aydin', 'name': 'phone', 'price': 50, 'username': 'kaan'},\n", 367 | " {'city': 'Istanbul', 'name': 'computer', 'price': 150, 'username': 'batu'}]" 368 | ] 369 | }, 370 | "metadata": {}, 371 | "execution_count": 50 372 | } 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "source": [ 378 | "def get_total_price():\n", 379 | " total_sum = 0\n", 380 | " for item in basket:\n", 381 | " total_sum += item['price']\n", 382 | " print(f\"Total sum is: {total_sum}\")\n", 383 | " return total_sum" 384 | ], 385 | "metadata": { 386 | "id": "DPrFXn3EidV2" 387 | }, 388 | "execution_count": 52, 389 | "outputs": [] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "source": [ 394 | "get_total_price()" 395 | ], 396 | "metadata": { 397 | "colab": { 398 | "base_uri": "https://localhost:8080/" 399 | }, 400 | "id": "XNSsNh6yinEb", 401 | "outputId": "844d95e3-a738-44f8-f829-40f4fff28116" 402 | }, 403 | "execution_count": 53, 404 | "outputs": [ 405 | { 406 | "output_type": "stream", 407 | "name": "stdout", 408 | "text": [ 409 | "Total sum is: 200\n" 410 | ] 411 | }, 412 | { 413 | "output_type": "execute_result", 414 | "data": { 415 | "text/plain": [ 416 | "200" 417 | ] 418 | }, 419 | "metadata": {}, 420 | "execution_count": 53 421 | } 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "source": [ 427 | "def get_all_cities():\n", 428 | " cities = []\n", 429 | " for item in basket:\n", 430 | " cities.append(item['city'])\n", 431 | " return set(cities)" 432 | ], 433 | "metadata": { 434 | "id": "yEhFAa5rirk-" 435 | }, 436 | "execution_count": 55, 437 | "outputs": [] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "source": [ 442 | "get_all_cities()" 443 | ], 444 | "metadata": { 445 | "colab": { 446 | "base_uri": "https://localhost:8080/" 447 | }, 448 | "id": "KuF5eA3HjVN6", 449 | "outputId": "9f74873c-feba-4264-a455-cb3f1b952402" 450 | }, 451 | "execution_count": 56, 452 | "outputs": [ 453 | { 454 | "output_type": "execute_result", 455 | "data": { 456 | "text/plain": [ 457 | "{'Aydin', 'Istanbul'}" 458 | ] 459 | }, 460 | "metadata": {}, 461 | "execution_count": 56 462 | } 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "source": [ 468 | "bottle = create_item(username=\"ali\", city=\"Istanbul\", name=\"bottle\", price=30)" 469 | ], 470 | "metadata": { 471 | "id": "mFQxSByEjWEw" 472 | }, 473 | "execution_count": 58, 474 | "outputs": [] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "source": [ 479 | "add_to_cart(bottle)" 480 | ], 481 | "metadata": { 482 | "colab": { 483 | "base_uri": "https://localhost:8080/" 484 | }, 485 | "id": "yptsXbB5jjor", 486 | "outputId": "276a894f-5d9b-4b5a-f7ce-1ecf03ec9b08" 487 | }, 488 | "execution_count": 59, 489 | "outputs": [ 490 | { 491 | "output_type": "stream", 492 | "name": "stdout", 493 | "text": [ 494 | "check item returned True\n", 495 | "bottle added to basket\n" 496 | ] 497 | } 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "source": [ 503 | "basket" 504 | ], 505 | "metadata": { 506 | "colab": { 507 | "base_uri": "https://localhost:8080/" 508 | }, 509 | "id": "zsGJBTcFjpAB", 510 | "outputId": "af6e9c57-771d-4e1c-cc24-f6ce3963d816" 511 | }, 512 | "execution_count": 60, 513 | "outputs": [ 514 | { 515 | "output_type": "execute_result", 516 | "data": { 517 | "text/plain": [ 518 | "[{'city': 'Aydin', 'name': 'phone', 'price': 50, 'username': 'kaan'},\n", 519 | " {'city': 'Istanbul', 'name': 'computer', 'price': 150, 'username': 'batu'},\n", 520 | " {'city': 'Istanbul', 'name': 'bottle', 'price': 30, 'username': 'ali'}]" 521 | ] 522 | }, 523 | "metadata": {}, 524 | "execution_count": 60 525 | } 526 | ] 527 | }, 528 | { 529 | "cell_type": "code", 530 | "source": [ 531 | "get_all_cities()" 532 | ], 533 | "metadata": { 534 | "colab": { 535 | "base_uri": "https://localhost:8080/" 536 | }, 537 | "id": "M8UDTjLTjp60", 538 | "outputId": "45948830-7b9a-4163-fd37-74f79f5d355d" 539 | }, 540 | "execution_count": 61, 541 | "outputs": [ 542 | { 543 | "output_type": "execute_result", 544 | "data": { 545 | "text/plain": [ 546 | "{'Aydin', 'Istanbul'}" 547 | ] 548 | }, 549 | "metadata": {}, 550 | "execution_count": 61 551 | } 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "source": [ 557 | "get_total_price()" 558 | ], 559 | "metadata": { 560 | "colab": { 561 | "base_uri": "https://localhost:8080/" 562 | }, 563 | "id": "NM_SHt3yjrd6", 564 | "outputId": "b53cd669-ceef-4837-a674-03e53081b626" 565 | }, 566 | "execution_count": 62, 567 | "outputs": [ 568 | { 569 | "output_type": "stream", 570 | "name": "stdout", 571 | "text": [ 572 | "Total sum is: 230\n" 573 | ] 574 | }, 575 | { 576 | "output_type": "execute_result", 577 | "data": { 578 | "text/plain": [ 579 | "230" 580 | ] 581 | }, 582 | "metadata": {}, 583 | "execution_count": 62 584 | } 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "source": [ 590 | "" 591 | ], 592 | "metadata": { 593 | "id": "D4yEvL_Ujz5S" 594 | }, 595 | "execution_count": null, 596 | "outputs": [] 597 | } 598 | ] 599 | } -------------------------------------------------------------------------------- /python101.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "dummy", 7 | "provenance": [], 8 | "collapsed_sections": [ 9 | "dKZEpcaV5XWd", 10 | "KccyzwAmtwrF", 11 | "w2Wl-Wuw7Khq", 12 | "xg88egnp_7eL", 13 | "85lFgov2T2WU", 14 | "wXu6NSu7U4YV", 15 | "eVVMDXLIXp9D", 16 | "EOsjC5OuacXb", 17 | "HikbgS1Ya9gF", 18 | "_ewXvsYFbiV4", 19 | "I7j5P9pssw2W" 20 | ], 21 | "toc_visible": true, 22 | "authorship_tag": "ABX9TyO1nJ9OXlEgg7lyCgIHE7RZ", 23 | "include_colab_link": true 24 | }, 25 | "kernelspec": { 26 | "name": "python3", 27 | "display_name": "Python 3" 28 | }, 29 | "language_info": { 30 | "name": "python" 31 | } 32 | }, 33 | "cells": [ 34 | { 35 | "cell_type": "markdown", 36 | "metadata": { 37 | "id": "view-in-github", 38 | "colab_type": "text" 39 | }, 40 | "source": [ 41 | "\"Open" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "source": [ 47 | "ÇiçekSepeti - Senior Cloud Data Engineer\n", 48 | "----\n", 49 | "#### http://kaanozbudak.com/\n", 50 | "#### https://linkedin.com/in/kaanozbudak/\n", 51 | "#### https://kaanozbudak.medium.com/\n", 52 | "#### https://instagram.com/kaanozbudakcom/\n", 53 | "#### https://twitter.com/kaanozbudakcom\n", 54 | "#### https://github.com/kaanozbudak\n", 55 | "----\n", 56 | "#### https://github.com/kaanozbudak/Python101" 57 | ], 58 | "metadata": { 59 | "id": "iGel1N44uVrt" 60 | } 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "source": [ 65 | "# Data Types\n", 66 | "Simply DataTypes is a way to represent values in Python. The types listed below are the most commonly used data types in Python.\n", 67 | "\n", 68 | "- int (represents numbers)\n", 69 | "- float (represents decimals)\n", 70 | "- str (represents text)\n", 71 | "- bool (represents bool values)\n", 72 | "- list (list of something)\n", 73 | "- dict (dictionary)\n", 74 | "- tuple (store multiple items in a single variable)\n", 75 | "- set (Duplicate values will be ignored)" 76 | ], 77 | "metadata": { 78 | "id": "dKZEpcaV5XWd" 79 | } 80 | }, 81 | { 82 | "cell_type": "code", 83 | "source": [ 84 | "num = 10 #int # declaring variable\n", 85 | "print(type(num)) # \n", 86 | "\n", 87 | "num = 9.99\n", 88 | "print(type(num)) # \n", 89 | "\n", 90 | "num2 = 1.8\n", 91 | "\n", 92 | "expression1 = num * 10\n", 93 | "print(type(expression1)) # \n", 94 | "\n", 95 | "expression2 = num + num2\n", 96 | "print(type(expression2)) # \n", 97 | "\n", 98 | "result = 10 + 19.8\n", 99 | "print(result)\n", 100 | "print(type(result))" 101 | ], 102 | "metadata": { 103 | "colab": { 104 | "base_uri": "https://localhost:8080/" 105 | }, 106 | "id": "Zznyr1FB6C-f", 107 | "outputId": "2bfef820-72e2-4138-c4c8-c518563a84f6" 108 | }, 109 | "execution_count": null, 110 | "outputs": [ 111 | { 112 | "output_type": "stream", 113 | "name": "stdout", 114 | "text": [ 115 | "\n", 116 | "\n", 117 | "\n", 118 | "\n", 119 | "29.8\n", 120 | "\n" 121 | ] 122 | } 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "source": [ 128 | "print(round(2.1)) # 2 returns a floating point number that is a rounded version of the specified number\n", 129 | "print(round(5.9)) # 6 \n", 130 | "print(abs(-34)) # 34 returns the absolute value of a number" 131 | ], 132 | "metadata": { 133 | "colab": { 134 | "base_uri": "https://localhost:8080/" 135 | }, 136 | "id": "HAeTyGvX6IK2", 137 | "outputId": "59103d3b-4e19-49f1-dce1-bfe4dc81a8aa" 138 | }, 139 | "execution_count": null, 140 | "outputs": [ 141 | { 142 | "output_type": "stream", 143 | "name": "stdout", 144 | "text": [ 145 | "2\n", 146 | "6\n", 147 | "34\n" 148 | ] 149 | } 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "source": [ 155 | "x = 11 # int\n", 156 | "\n", 157 | "print(x+2) # Sum #12 # int\n", 158 | "print(x-2) # Diff # 8 # int\n", 159 | "print(x*2) # Multiplication #20 #int\n", 160 | "print(x/2) # Division # 5 #int # will result with remainders\n", 161 | "\n", 162 | "print(x**2) # Exponential \n", 163 | "print(x//2) # Divide (without remainder)\n", 164 | "print(x%2) # Mod (Remainder)" 165 | ], 166 | "metadata": { 167 | "colab": { 168 | "base_uri": "https://localhost:8080/" 169 | }, 170 | "id": "WSrVOEFw6gL7", 171 | "outputId": "092181ed-be15-4bd8-f297-540dd637eb8f" 172 | }, 173 | "execution_count": null, 174 | "outputs": [ 175 | { 176 | "output_type": "stream", 177 | "name": "stdout", 178 | "text": [ 179 | "13\n", 180 | "9\n", 181 | "22\n", 182 | "5.5\n", 183 | "121\n", 184 | "5\n", 185 | "1\n" 186 | ] 187 | } 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "source": [ 193 | "# Casting\n", 194 | "You can spesicfy data type in python" 195 | ], 196 | "metadata": { 197 | "id": "KccyzwAmtwrF" 198 | } 199 | }, 200 | { 201 | "cell_type": "code", 202 | "source": [ 203 | "print(5)\n", 204 | "print(type(5))\n", 205 | "print(str(5))\n", 206 | "print(type(str(5)))" 207 | ], 208 | "metadata": { 209 | "colab": { 210 | "base_uri": "https://localhost:8080/" 211 | }, 212 | "id": "ot3xHpsftxhR", 213 | "outputId": "a9620488-c127-4c8a-bea6-026710234e3c" 214 | }, 215 | "execution_count": 78, 216 | "outputs": [ 217 | { 218 | "output_type": "stream", 219 | "name": "stdout", 220 | "text": [ 221 | "5\n", 222 | "\n", 223 | "5\n", 224 | "\n" 225 | ] 226 | } 227 | ] 228 | }, 229 | { 230 | "cell_type": "markdown", 231 | "source": [ 232 | "# Variables\n", 233 | "Variables store values. The following are the naming conventions in Python:\n", 234 | "Variables must begin with a letter (preferably lowercase) or an underscore followed by numbers or an underscore\n", 235 | "Snake case is the traditional way of writing variable with multiple words like user_name\n", 236 | "They are case sensitive\n", 237 | "Keywords should not be overwritten by keywords (Python keywords)" 238 | ], 239 | "metadata": { 240 | "id": "w2Wl-Wuw7Khq" 241 | } 242 | }, 243 | { 244 | "cell_type": "code", 245 | "source": [ 246 | "name = 'kaan'\n", 247 | "surname = 'ozbudak'\n", 248 | "age = 25\n", 249 | "print(name)\n", 250 | "print(age)\n", 251 | "print(name + surname)\n", 252 | "print(name + \" \" + surname)\n", 253 | "print(name)\n", 254 | "print(type(name))\n", 255 | "print(type(age))" 256 | ], 257 | "metadata": { 258 | "colab": { 259 | "base_uri": "https://localhost:8080/" 260 | }, 261 | "id": "TedEmcbR7NuX", 262 | "outputId": "86fe96c4-906a-4174-d8fc-d3d76e69c593" 263 | }, 264 | "execution_count": null, 265 | "outputs": [ 266 | { 267 | "output_type": "stream", 268 | "name": "stdout", 269 | "text": [ 270 | "kaan\n", 271 | "25\n", 272 | "kaanozbudak\n", 273 | "kaan ozbudak\n", 274 | "kaan\n", 275 | "\n", 276 | "\n" 277 | ] 278 | } 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "source": [ 284 | "pname * age" 285 | ], 286 | "metadata": { 287 | "colab": { 288 | "base_uri": "https://localhost:8080/", 289 | "height": 35 290 | }, 291 | "id": "nB5v1kZY91VN", 292 | "outputId": "1d656205-8a5f-4477-9ce2-48da671af01c" 293 | }, 294 | "execution_count": null, 295 | "outputs": [ 296 | { 297 | "output_type": "execute_result", 298 | "data": { 299 | "text/plain": [ 300 | "'kaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaankaan'" 301 | ], 302 | "application/vnd.google.colaboratory.intrinsic+json": { 303 | "type": "string" 304 | } 305 | }, 306 | "metadata": {}, 307 | "execution_count": 14 308 | } 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "source": [ 314 | "title = input(\"give me your title: \")\n", 315 | "print(\"your title is: \" + title)" 316 | ], 317 | "metadata": { 318 | "colab": { 319 | "base_uri": "https://localhost:8080/" 320 | }, 321 | "id": "oE4L-f78-U8X", 322 | "outputId": "09a4fa1f-204f-4407-db15-c5094823b118" 323 | }, 324 | "execution_count": null, 325 | "outputs": [ 326 | { 327 | "output_type": "stream", 328 | "name": "stdout", 329 | "text": [ 330 | "give me your title: dat\n", 331 | "your title is: dat\n" 332 | ] 333 | } 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "source": [ 339 | "print(f\"Your name is {name} and your surname is {surname} and your age is {age}\")" 340 | ], 341 | "metadata": { 342 | "colab": { 343 | "base_uri": "https://localhost:8080/" 344 | }, 345 | "id": "fYgcXgXM-bRm", 346 | "outputId": "52efb50d-0a68-4310-d33c-0640de8cc4b6" 347 | }, 348 | "execution_count": null, 349 | "outputs": [ 350 | { 351 | "output_type": "stream", 352 | "name": "stdout", 353 | "text": [ 354 | "Your name is kaan and your surname is ozbudak and your age is 25\n" 355 | ] 356 | } 357 | ] 358 | }, 359 | { 360 | "cell_type": "code", 361 | "source": [ 362 | "title" 363 | ], 364 | "metadata": { 365 | "colab": { 366 | "base_uri": "https://localhost:8080/", 367 | "height": 35 368 | }, 369 | "id": "-DZ_hUsN-19N", 370 | "outputId": "138ddd69-2252-460b-e834-67ac281e31e2" 371 | }, 372 | "execution_count": null, 373 | "outputs": [ 374 | { 375 | "output_type": "execute_result", 376 | "data": { 377 | "text/plain": [ 378 | "'dat'" 379 | ], 380 | "application/vnd.google.colaboratory.intrinsic+json": { 381 | "type": "string" 382 | } 383 | }, 384 | "metadata": {}, 385 | "execution_count": 21 386 | } 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "source": [ 392 | "surname[0]" 393 | ], 394 | "metadata": { 395 | "colab": { 396 | "base_uri": "https://localhost:8080/", 397 | "height": 35 398 | }, 399 | "id": "OYuA0exS-6Ks", 400 | "outputId": "a0692a3c-8cb8-4522-c392-4fb26ea8541d" 401 | }, 402 | "execution_count": null, 403 | "outputs": [ 404 | { 405 | "output_type": "execute_result", 406 | "data": { 407 | "text/plain": [ 408 | "'o'" 409 | ], 410 | "application/vnd.google.colaboratory.intrinsic+json": { 411 | "type": "string" 412 | } 413 | }, 414 | "metadata": {}, 415 | "execution_count": 22 416 | } 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "source": [ 422 | "first_character = surname[0] # indexing starts from 0\n", 423 | "last_character = surname[-1]\n", 424 | "print(first_character)\n", 425 | "print(last_character)\n", 426 | "print(surname[1:4])\n", 427 | "print(surname[2:])" 428 | ], 429 | "metadata": { 430 | "colab": { 431 | "base_uri": "https://localhost:8080/" 432 | }, 433 | "id": "VXr8JVhz-8Ua", 434 | "outputId": "14f16609-aab1-4071-a2b7-47218a99aa63" 435 | }, 436 | "execution_count": null, 437 | "outputs": [ 438 | { 439 | "output_type": "stream", 440 | "name": "stdout", 441 | "text": [ 442 | "o\n", 443 | "k\n", 444 | "zbu\n", 445 | "budak\n" 446 | ] 447 | } 448 | ] 449 | }, 450 | { 451 | "cell_type": "markdown", 452 | "source": [ 453 | "Booleans stores only True or False values." 454 | ], 455 | "metadata": { 456 | "id": "gFKzDmVm_Wpf" 457 | } 458 | }, 459 | { 460 | "cell_type": "code", 461 | "source": [ 462 | "status = True\n", 463 | "approved = False\n", 464 | "print(status)\n", 465 | "print(type(approved))\n", 466 | "\n", 467 | "print(10 > 8)\n", 468 | "print(name == surname)\n", 469 | "\n", 470 | "password = \"12345\"\n", 471 | "\n", 472 | "print(password==\"12345\")\n", 473 | "\n", 474 | "print(True and False)\n", 475 | "print(True and True)" 476 | ], 477 | "metadata": { 478 | "colab": { 479 | "base_uri": "https://localhost:8080/" 480 | }, 481 | "id": "s8igMsMa_XM-", 482 | "outputId": "18eebf74-632f-4449-928e-a434f0166c96" 483 | }, 484 | "execution_count": null, 485 | "outputs": [ 486 | { 487 | "output_type": "stream", 488 | "name": "stdout", 489 | "text": [ 490 | "True\n", 491 | "\n", 492 | "True\n", 493 | "False\n", 494 | "True\n", 495 | "False\n", 496 | "True\n" 497 | ] 498 | } 499 | ] 500 | }, 501 | { 502 | "cell_type": "markdown", 503 | "source": [ 504 | " # List\n", 505 | " List is an organized collection of objects. It is also a data structure, meaning a container that organizes data in a certain way for different purposes. They are denoted by []. They can be used to store the same or different types of data together." 506 | ], 507 | "metadata": { 508 | "id": "xg88egnp_7eL" 509 | } 510 | }, 511 | { 512 | "cell_type": "code", 513 | "source": [ 514 | "fruits = [\"apple\", \"orange\", \"banana\"]\n", 515 | "\n", 516 | "names = []\n", 517 | "print(names)\n", 518 | "names.append(\"kaan\")\n", 519 | "print(names)\n", 520 | "print(len(names))\n", 521 | "print(names[0]) # first item of list\n", 522 | "names.append(\"ali\")\n", 523 | "names.insert(0, \"veli\")\n", 524 | "print(\"inserted\")\n", 525 | "print(names)\n", 526 | "names.pop()\n", 527 | "print(\"pop item\")\n", 528 | "print(names)\n", 529 | "names.remove('kaan')\n", 530 | "print(\"remove item\")\n", 531 | "print(names) # ali\n", 532 | "names.clear()\n", 533 | "print(\"clear items\")\n", 534 | "print(names) # []" 535 | ], 536 | "metadata": { 537 | "colab": { 538 | "base_uri": "https://localhost:8080/" 539 | }, 540 | "id": "a_B_TlJc_9w_", 541 | "outputId": "1769e5a6-8d3f-4b4f-ff7c-7d65ad98d468" 542 | }, 543 | "execution_count": null, 544 | "outputs": [ 545 | { 546 | "output_type": "stream", 547 | "name": "stdout", 548 | "text": [ 549 | "[]\n", 550 | "['kaan']\n", 551 | "1\n", 552 | "kaan\n", 553 | "inserted\n", 554 | "['veli', 'kaan', 'ali']\n", 555 | "pop item\n", 556 | "['veli', 'kaan']\n", 557 | "remove item\n", 558 | "['veli']\n", 559 | "clear items\n", 560 | "[]\n" 561 | ] 562 | } 563 | ] 564 | }, 565 | { 566 | "cell_type": "code", 567 | "source": [ 568 | "random_numbers = [1,2,3,1,3,4,2,5,6]\n", 569 | "count_two = random_numbers.count('2') # count 2\n", 570 | "random_numbers.sort()\n", 571 | "print(random_numbers) # sort numbers\n", 572 | "random_numbers.reverse()\n", 573 | "print(random_numbers) # reverse side" 574 | ], 575 | "metadata": { 576 | "id": "8tzDFm3wAJja", 577 | "colab": { 578 | "base_uri": "https://localhost:8080/" 579 | }, 580 | "outputId": "fcda0ebb-19e0-49f8-d397-259e00127649" 581 | }, 582 | "execution_count": null, 583 | "outputs": [ 584 | { 585 | "output_type": "stream", 586 | "name": "stdout", 587 | "text": [ 588 | "[1, 1, 2, 2, 3, 3, 4, 5, 6]\n", 589 | "[6, 5, 4, 3, 3, 2, 2, 1, 1]\n" 590 | ] 591 | } 592 | ] 593 | }, 594 | { 595 | "cell_type": "markdown", 596 | "source": [ 597 | "# Dictionaries\n", 598 | "Dictionaries are used to store data values in key:value pairs.\n", 599 | "\n", 600 | "A dictionary is a collection which is ordered*, changeable and do not allow duplicates.\n" 601 | ], 602 | "metadata": { 603 | "id": "85lFgov2T2WU" 604 | } 605 | }, 606 | { 607 | "cell_type": "code", 608 | "source": [ 609 | "user = {\n", 610 | " \"name\": \"kaan\",\n", 611 | " \"surname\": \"ozbudak\",\n", 612 | " \"age\": 25,\n", 613 | " \"is_student\": True,\n", 614 | " \"is_married\": False\n", 615 | "}\n", 616 | "\n", 617 | "print(user['age'])\n", 618 | "\n", 619 | "print(user['is_student'])\n", 620 | "\n", 621 | "user['title'] = \"Data Engineer\"\n", 622 | "\n", 623 | "print(user)\n", 624 | "\n", 625 | "user['age'] = user['age'] + 1 \n", 626 | "\n", 627 | "print(user)\n", 628 | "\n", 629 | "print(user.keys())\n", 630 | "print(user.values())" 631 | ], 632 | "metadata": { 633 | "colab": { 634 | "base_uri": "https://localhost:8080/" 635 | }, 636 | "id": "jtmpK335UALp", 637 | "outputId": "dcbc6144-80af-47ca-d946-e2a2e82be529" 638 | }, 639 | "execution_count": null, 640 | "outputs": [ 641 | { 642 | "output_type": "stream", 643 | "name": "stdout", 644 | "text": [ 645 | "25\n", 646 | "True\n", 647 | "{'name': 'kaan', 'surname': 'ozbudak', 'age': 25, 'is_student': True, 'is_married': False, 'title': 'Data Engineer'}\n", 648 | "{'name': 'kaan', 'surname': 'ozbudak', 'age': 26, 'is_student': True, 'is_married': False, 'title': 'Data Engineer'}\n", 649 | "dict_keys(['name', 'surname', 'age', 'is_student', 'is_married', 'title'])\n", 650 | "dict_values(['kaan', 'ozbudak', 26, True, False, 'Data Engineer'])\n" 651 | ] 652 | } 653 | ] 654 | }, 655 | { 656 | "cell_type": "markdown", 657 | "source": [ 658 | "# Conditions\n", 659 | "Python Conditions and If statements\n", 660 | "Python supports the usual logical conditions from mathematics:\n", 661 | "\n", 662 | "Equals: a == b\n", 663 | "Not Equals: a != b\n", 664 | "Less than: a < b\n", 665 | "Less than or equal to: a <= b\n", 666 | "Greater than: a > b\n", 667 | "Greater than or equal to: a >= b" 668 | ], 669 | "metadata": { 670 | "id": "wXu6NSu7U4YV" 671 | } 672 | }, 673 | { 674 | "cell_type": "code", 675 | "source": [ 676 | "print(user[\"name\"] == \"kaan\") # True\n", 677 | "\n", 678 | "print(user[\"age\"] >= 30) # False" 679 | ], 680 | "metadata": { 681 | "colab": { 682 | "base_uri": "https://localhost:8080/" 683 | }, 684 | "id": "uKhw7CJHU_se", 685 | "outputId": "47233dff-01fe-4fe0-897f-5b8d762ef766" 686 | }, 687 | "execution_count": null, 688 | "outputs": [ 689 | { 690 | "output_type": "stream", 691 | "name": "stdout", 692 | "text": [ 693 | "True\n", 694 | "False\n" 695 | ] 696 | } 697 | ] 698 | }, 699 | { 700 | "cell_type": "code", 701 | "source": [ 702 | "if user[\"age\"] >= 18:\n", 703 | " print(\"you are old enough\")" 704 | ], 705 | "metadata": { 706 | "colab": { 707 | "base_uri": "https://localhost:8080/" 708 | }, 709 | "id": "O4c1a0cYVcZF", 710 | "outputId": "fbf4cceb-54cf-449f-e847-dd038497bb85" 711 | }, 712 | "execution_count": null, 713 | "outputs": [ 714 | { 715 | "output_type": "stream", 716 | "name": "stdout", 717 | "text": [ 718 | "you are old enough\n" 719 | ] 720 | } 721 | ] 722 | }, 723 | { 724 | "cell_type": "code", 725 | "source": [ 726 | "if user[\"age\"] >= 30:\n", 727 | " print(\"you are old enough\")\n", 728 | "else:\n", 729 | " print(\"not now!\")" 730 | ], 731 | "metadata": { 732 | "colab": { 733 | "base_uri": "https://localhost:8080/" 734 | }, 735 | "id": "imnYWdJzVlmT", 736 | "outputId": "e9af8b30-2dd3-4c8a-dd1a-ceb827e3d918" 737 | }, 738 | "execution_count": null, 739 | "outputs": [ 740 | { 741 | "output_type": "stream", 742 | "name": "stdout", 743 | "text": [ 744 | "not now!\n" 745 | ] 746 | } 747 | ] 748 | }, 749 | { 750 | "cell_type": "code", 751 | "source": [ 752 | "user" 753 | ], 754 | "metadata": { 755 | "colab": { 756 | "base_uri": "https://localhost:8080/" 757 | }, 758 | "id": "jSRbOeeVVry3", 759 | "outputId": "ad918de8-ab7d-47df-a95e-5460dba0542d" 760 | }, 761 | "execution_count": null, 762 | "outputs": [ 763 | { 764 | "output_type": "execute_result", 765 | "data": { 766 | "text/plain": [ 767 | "{'age': 26,\n", 768 | " 'is_married': False,\n", 769 | " 'is_student': True,\n", 770 | " 'name': 'kaan',\n", 771 | " 'surname': 'ozbudak',\n", 772 | " 'title': 'Data Engineer'}" 773 | ] 774 | }, 775 | "metadata": {}, 776 | "execution_count": 16 777 | } 778 | ] 779 | }, 780 | { 781 | "cell_type": "code", 782 | "source": [ 783 | "user['email'] = \"kaanozbudak@hotmail.com\"\n", 784 | "user['password'] = \"12345\"" 785 | ], 786 | "metadata": { 787 | "id": "2y-9WsCwVwyy" 788 | }, 789 | "execution_count": null, 790 | "outputs": [] 791 | }, 792 | { 793 | "cell_type": "code", 794 | "source": [ 795 | "user" 796 | ], 797 | "metadata": { 798 | "colab": { 799 | "base_uri": "https://localhost:8080/" 800 | }, 801 | "id": "hNZCAOyKV2pD", 802 | "outputId": "9e92f324-4ac7-49dd-d7a8-1deb8f359553" 803 | }, 804 | "execution_count": null, 805 | "outputs": [ 806 | { 807 | "output_type": "execute_result", 808 | "data": { 809 | "text/plain": [ 810 | "{'age': 26,\n", 811 | " 'email': 'kaanozbudak@hotmail.com',\n", 812 | " 'is_married': False,\n", 813 | " 'is_student': True,\n", 814 | " 'name': 'kaan',\n", 815 | " 'password': '12345',\n", 816 | " 'surname': 'ozbudak',\n", 817 | " 'title': 'Data Engineer'}" 818 | ] 819 | }, 820 | "metadata": {}, 821 | "execution_count": 18 822 | } 823 | ] 824 | }, 825 | { 826 | "cell_type": "code", 827 | "source": [ 828 | "print(\"Login Screen\")\n", 829 | "email_input = input(\"Please enter your email: \")\n", 830 | "password_input = input(\"Please give your password: \")\n", 831 | "\n", 832 | "if (email_input != user['email']) or (password_input != user['password']):\n", 833 | " print(\"Email or password wrong\")\n", 834 | "elif (email_input == user['email']) and (password_input == user['password']):\n", 835 | " print(\"Come in, correct auth!\")" 836 | ], 837 | "metadata": { 838 | "colab": { 839 | "base_uri": "https://localhost:8080/" 840 | }, 841 | "id": "F-gCT_H8V3LH", 842 | "outputId": "461aa72f-f834-4fcc-faa9-c202fd1deda9" 843 | }, 844 | "execution_count": null, 845 | "outputs": [ 846 | { 847 | "output_type": "stream", 848 | "name": "stdout", 849 | "text": [ 850 | "Login Screen\n", 851 | "Please enter your email: kaanozbudak@hotmail.com\n", 852 | "Please give your password: 1234\n", 853 | "Email or password wrong\n" 854 | ] 855 | } 856 | ] 857 | }, 858 | { 859 | "cell_type": "markdown", 860 | "source": [ 861 | "# Loops \n", 862 | "loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string)" 863 | ], 864 | "metadata": { 865 | "id": "eVVMDXLIXp9D" 866 | } 867 | }, 868 | { 869 | "cell_type": "code", 870 | "source": [ 871 | "random_numbers" 872 | ], 873 | "metadata": { 874 | "colab": { 875 | "base_uri": "https://localhost:8080/" 876 | }, 877 | "id": "FbUUIaLEWp2B", 878 | "outputId": "99e48857-9ad8-496f-9c39-870091403522" 879 | }, 880 | "execution_count": null, 881 | "outputs": [ 882 | { 883 | "output_type": "execute_result", 884 | "data": { 885 | "text/plain": [ 886 | "[6, 5, 4, 3, 3, 2, 2, 1, 1]" 887 | ] 888 | }, 889 | "metadata": {}, 890 | "execution_count": 22 891 | } 892 | ] 893 | }, 894 | { 895 | "cell_type": "code", 896 | "source": [ 897 | "for number in random_numbers:\n", 898 | " print(number)" 899 | ], 900 | "metadata": { 901 | "colab": { 902 | "base_uri": "https://localhost:8080/" 903 | }, 904 | "id": "IfEtjABaW2bH", 905 | "outputId": "e766371d-98fe-4778-e7eb-2c1add7f0cfc" 906 | }, 907 | "execution_count": null, 908 | "outputs": [ 909 | { 910 | "output_type": "stream", 911 | "name": "stdout", 912 | "text": [ 913 | "6\n", 914 | "5\n", 915 | "4\n", 916 | "3\n", 917 | "3\n", 918 | "2\n", 919 | "2\n", 920 | "1\n", 921 | "1\n" 922 | ] 923 | } 924 | ] 925 | }, 926 | { 927 | "cell_type": "code", 928 | "source": [ 929 | "for number in random_numbers:\n", 930 | " print(number * 10)" 931 | ], 932 | "metadata": { 933 | "colab": { 934 | "base_uri": "https://localhost:8080/" 935 | }, 936 | "id": "GbUQSjl0W8ca", 937 | "outputId": "5f209a97-c838-40e8-eafa-598b75e48b79" 938 | }, 939 | "execution_count": null, 940 | "outputs": [ 941 | { 942 | "output_type": "stream", 943 | "name": "stdout", 944 | "text": [ 945 | "60\n", 946 | "50\n", 947 | "40\n", 948 | "30\n", 949 | "30\n", 950 | "20\n", 951 | "20\n", 952 | "10\n", 953 | "10\n" 954 | ] 955 | } 956 | ] 957 | }, 958 | { 959 | "cell_type": "code", 960 | "source": [ 961 | "for letter in \"kaanozbudak\":\n", 962 | " print(letter)" 963 | ], 964 | "metadata": { 965 | "colab": { 966 | "base_uri": "https://localhost:8080/" 967 | }, 968 | "id": "Ac0TiZdjXAp5", 969 | "outputId": "fd25130d-6769-416d-b7b3-4b435e056558" 970 | }, 971 | "execution_count": null, 972 | "outputs": [ 973 | { 974 | "output_type": "stream", 975 | "name": "stdout", 976 | "text": [ 977 | "k\n", 978 | "a\n", 979 | "a\n", 980 | "n\n", 981 | "o\n", 982 | "z\n", 983 | "b\n", 984 | "u\n", 985 | "d\n", 986 | "a\n", 987 | "k\n" 988 | ] 989 | } 990 | ] 991 | }, 992 | { 993 | "cell_type": "code", 994 | "source": [ 995 | "user" 996 | ], 997 | "metadata": { 998 | "colab": { 999 | "base_uri": "https://localhost:8080/" 1000 | }, 1001 | "id": "pEsNrZD0XF82", 1002 | "outputId": "714de091-6bcc-4e11-bb02-2aa8f85957fc" 1003 | }, 1004 | "execution_count": null, 1005 | "outputs": [ 1006 | { 1007 | "output_type": "execute_result", 1008 | "data": { 1009 | "text/plain": [ 1010 | "{'age': 26,\n", 1011 | " 'email': 'kaanozbudak@hotmail.com',\n", 1012 | " 'is_married': False,\n", 1013 | " 'is_student': True,\n", 1014 | " 'name': 'kaan',\n", 1015 | " 'password': '12345',\n", 1016 | " 'surname': 'ozbudak',\n", 1017 | " 'title': 'Data Engineer'}" 1018 | ] 1019 | }, 1020 | "metadata": {}, 1021 | "execution_count": 27 1022 | } 1023 | ] 1024 | }, 1025 | { 1026 | "cell_type": "code", 1027 | "source": [ 1028 | "for key in user.keys():\n", 1029 | " print(key)" 1030 | ], 1031 | "metadata": { 1032 | "colab": { 1033 | "base_uri": "https://localhost:8080/" 1034 | }, 1035 | "id": "vcv2TgCWXJ68", 1036 | "outputId": "a346c8b5-f825-4010-bc97-74b426798c92" 1037 | }, 1038 | "execution_count": null, 1039 | "outputs": [ 1040 | { 1041 | "output_type": "stream", 1042 | "name": "stdout", 1043 | "text": [ 1044 | "name\n", 1045 | "surname\n", 1046 | "age\n", 1047 | "is_student\n", 1048 | "is_married\n", 1049 | "title\n", 1050 | "email\n", 1051 | "password\n" 1052 | ] 1053 | } 1054 | ] 1055 | }, 1056 | { 1057 | "cell_type": "code", 1058 | "source": [ 1059 | "for value in user.values():\n", 1060 | " print(value)" 1061 | ], 1062 | "metadata": { 1063 | "colab": { 1064 | "base_uri": "https://localhost:8080/" 1065 | }, 1066 | "id": "BjAtdPEAXMpD", 1067 | "outputId": "64a71da9-9214-4090-c9af-d52a3eba4035" 1068 | }, 1069 | "execution_count": null, 1070 | "outputs": [ 1071 | { 1072 | "output_type": "stream", 1073 | "name": "stdout", 1074 | "text": [ 1075 | "kaan\n", 1076 | "ozbudak\n", 1077 | "26\n", 1078 | "True\n", 1079 | "False\n", 1080 | "Data Engineer\n", 1081 | "kaanozbudak@hotmail.com\n", 1082 | "12345\n" 1083 | ] 1084 | } 1085 | ] 1086 | }, 1087 | { 1088 | "cell_type": "code", 1089 | "source": [ 1090 | "for key, value in user.items():\n", 1091 | " print(f\"key: {key}\")\n", 1092 | " print(f\"value: {value}\")\n", 1093 | " print(\"-----\")" 1094 | ], 1095 | "metadata": { 1096 | "colab": { 1097 | "base_uri": "https://localhost:8080/" 1098 | }, 1099 | "id": "tlhoaTtCXPhd", 1100 | "outputId": "f758527e-ce17-4fde-9408-4e8151d4bd31" 1101 | }, 1102 | "execution_count": null, 1103 | "outputs": [ 1104 | { 1105 | "output_type": "stream", 1106 | "name": "stdout", 1107 | "text": [ 1108 | "key: name\n", 1109 | "value: kaan\n", 1110 | "-----\n", 1111 | "key: surname\n", 1112 | "value: ozbudak\n", 1113 | "-----\n", 1114 | "key: age\n", 1115 | "value: 26\n", 1116 | "-----\n", 1117 | "key: is_student\n", 1118 | "value: True\n", 1119 | "-----\n", 1120 | "key: is_married\n", 1121 | "value: False\n", 1122 | "-----\n", 1123 | "key: title\n", 1124 | "value: Data Engineer\n", 1125 | "-----\n", 1126 | "key: email\n", 1127 | "value: kaanozbudak@hotmail.com\n", 1128 | "-----\n", 1129 | "key: password\n", 1130 | "value: 12345\n", 1131 | "-----\n" 1132 | ] 1133 | } 1134 | ] 1135 | }, 1136 | { 1137 | "cell_type": "code", 1138 | "source": [ 1139 | "for counter in range(10):\n", 1140 | " print(counter)" 1141 | ], 1142 | "metadata": { 1143 | "colab": { 1144 | "base_uri": "https://localhost:8080/" 1145 | }, 1146 | "id": "S9ADO6EBXWnh", 1147 | "outputId": "583e56bc-20ae-484e-f627-5be85f352c9e" 1148 | }, 1149 | "execution_count": null, 1150 | "outputs": [ 1151 | { 1152 | "output_type": "stream", 1153 | "name": "stdout", 1154 | "text": [ 1155 | "0\n", 1156 | "1\n", 1157 | "2\n", 1158 | "3\n", 1159 | "4\n", 1160 | "5\n", 1161 | "6\n", 1162 | "7\n", 1163 | "8\n", 1164 | "9\n" 1165 | ] 1166 | } 1167 | ] 1168 | }, 1169 | { 1170 | "cell_type": "code", 1171 | "source": [ 1172 | "numbers_list = (x for x in range(10))\n", 1173 | "\n", 1174 | "numbers_list2 = []\n", 1175 | "\n", 1176 | "for x in range(10):\n", 1177 | " numbers_list2.append(x)\n", 1178 | "\n", 1179 | "\n", 1180 | "print(list(numbers_list))\n", 1181 | "print(numbers_list2)" 1182 | ], 1183 | "metadata": { 1184 | "colab": { 1185 | "base_uri": "https://localhost:8080/" 1186 | }, 1187 | "id": "Qkt2_0yZYBeX", 1188 | "outputId": "05c773c7-152a-4528-ffe0-6642173e91dc" 1189 | }, 1190 | "execution_count": null, 1191 | "outputs": [ 1192 | { 1193 | "output_type": "stream", 1194 | "name": "stdout", 1195 | "text": [ 1196 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", 1197 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n" 1198 | ] 1199 | } 1200 | ] 1201 | }, 1202 | { 1203 | "cell_type": "code", 1204 | "source": [ 1205 | "for number in numbers_list2:\n", 1206 | " if number % 2 == 1:\n", 1207 | " print(f\"odd: {number}\")\n", 1208 | " else:\n", 1209 | " print(f\"even: {number}\")" 1210 | ], 1211 | "metadata": { 1212 | "colab": { 1213 | "base_uri": "https://localhost:8080/" 1214 | }, 1215 | "id": "Yv_eF2nIYQnE", 1216 | "outputId": "86661f67-9d5b-4f35-e000-4063bc72a2cf" 1217 | }, 1218 | "execution_count": null, 1219 | "outputs": [ 1220 | { 1221 | "output_type": "stream", 1222 | "name": "stdout", 1223 | "text": [ 1224 | "even: 0\n", 1225 | "odd: 1\n", 1226 | "even: 2\n", 1227 | "odd: 3\n", 1228 | "even: 4\n", 1229 | "odd: 5\n", 1230 | "even: 6\n", 1231 | "odd: 7\n", 1232 | "even: 8\n", 1233 | "odd: 9\n" 1234 | ] 1235 | } 1236 | ] 1237 | }, 1238 | { 1239 | "cell_type": "code", 1240 | "source": [ 1241 | "while True:\n", 1242 | " # print(\"Hello world\")\n", 1243 | " break" 1244 | ], 1245 | "metadata": { 1246 | "id": "xbqiHUcHXfH_" 1247 | }, 1248 | "execution_count": null, 1249 | "outputs": [] 1250 | }, 1251 | { 1252 | "cell_type": "code", 1253 | "source": [ 1254 | "flag = True\n", 1255 | "counter = 0\n", 1256 | "while flag:\n", 1257 | " print(counter)\n", 1258 | " counter += 1\n", 1259 | " if counter == 4:\n", 1260 | " print(\"SKIP\")\n", 1261 | " if counter >= 10:\n", 1262 | " flag = False" 1263 | ], 1264 | "metadata": { 1265 | "colab": { 1266 | "base_uri": "https://localhost:8080/" 1267 | }, 1268 | "id": "A5Gij_q0YVwa", 1269 | "outputId": "1ee66ab8-b701-4c17-f061-d8d5e816b0d9" 1270 | }, 1271 | "execution_count": null, 1272 | "outputs": [ 1273 | { 1274 | "output_type": "stream", 1275 | "name": "stdout", 1276 | "text": [ 1277 | "0\n", 1278 | "1\n", 1279 | "2\n", 1280 | "3\n", 1281 | "SKIP\n", 1282 | "4\n", 1283 | "5\n", 1284 | "6\n", 1285 | "7\n", 1286 | "8\n", 1287 | "9\n" 1288 | ] 1289 | } 1290 | ] 1291 | }, 1292 | { 1293 | "cell_type": "markdown", 1294 | "source": [ 1295 | "# Tuples\n", 1296 | "Tuples are used to store multiple items in a single variable." 1297 | ], 1298 | "metadata": { 1299 | "id": "EOsjC5OuacXb" 1300 | } 1301 | }, 1302 | { 1303 | "cell_type": "code", 1304 | "source": [ 1305 | "ages = (12, 24, 25, 14)\n", 1306 | "\n", 1307 | "first_age = ages[0]\n", 1308 | "second_age = ages[1]\n", 1309 | "print(f\"first_age: {first_age}\")\n", 1310 | "print(f\"second_age: {second_age}\")" 1311 | ], 1312 | "metadata": { 1313 | "colab": { 1314 | "base_uri": "https://localhost:8080/" 1315 | }, 1316 | "id": "mMRaax8qajFQ", 1317 | "outputId": "ee8d06d0-b0c4-49c0-c033-65b3aae2d14c" 1318 | }, 1319 | "execution_count": null, 1320 | "outputs": [ 1321 | { 1322 | "output_type": "stream", 1323 | "name": "stdout", 1324 | "text": [ 1325 | "first_age: 12\n", 1326 | "second_age: 24\n" 1327 | ] 1328 | } 1329 | ] 1330 | }, 1331 | { 1332 | "cell_type": "markdown", 1333 | "source": [ 1334 | "# Sets\n", 1335 | "Sets are used to store multiple items in a single variable.\n", 1336 | "\n", 1337 | "Sets does not allow duplicate values.\n", 1338 | "\n" 1339 | ], 1340 | "metadata": { 1341 | "id": "HikbgS1Ya9gF" 1342 | } 1343 | }, 1344 | { 1345 | "cell_type": "code", 1346 | "source": [ 1347 | "set_example = {1,2,2,2,2,3,4,4,5,5,6,6}\n", 1348 | "print(set_example)" 1349 | ], 1350 | "metadata": { 1351 | "colab": { 1352 | "base_uri": "https://localhost:8080/" 1353 | }, 1354 | "id": "iupteB5SbDYy", 1355 | "outputId": "046b1705-a755-4494-9f8a-f33691d77b10" 1356 | }, 1357 | "execution_count": null, 1358 | "outputs": [ 1359 | { 1360 | "output_type": "stream", 1361 | "name": "stdout", 1362 | "text": [ 1363 | "{1, 2, 3, 4, 5, 6}\n" 1364 | ] 1365 | } 1366 | ] 1367 | }, 1368 | { 1369 | "cell_type": "code", 1370 | "source": [ 1371 | "my_list = [1,2,3,3,3,3,3,2,3,4,5]\n", 1372 | "print(my_list)\n", 1373 | "print(set(my_list))" 1374 | ], 1375 | "metadata": { 1376 | "colab": { 1377 | "base_uri": "https://localhost:8080/" 1378 | }, 1379 | "id": "f5qA99BYbOkj", 1380 | "outputId": "80ed849d-1d90-4294-be07-e338c295c817" 1381 | }, 1382 | "execution_count": null, 1383 | "outputs": [ 1384 | { 1385 | "output_type": "stream", 1386 | "name": "stdout", 1387 | "text": [ 1388 | "[1, 2, 3, 3, 3, 3, 3, 2, 3, 4, 5]\n", 1389 | "{1, 2, 3, 4, 5}\n" 1390 | ] 1391 | } 1392 | ] 1393 | }, 1394 | { 1395 | "cell_type": "markdown", 1396 | "source": [ 1397 | "# Functions\n", 1398 | "In Python, a function is a group of related statements that performs a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and \n", 1399 | "manageable. Furthermore, it avoids repetition and makes the code reusable." 1400 | ], 1401 | "metadata": { 1402 | "id": "_ewXvsYFbiV4" 1403 | } 1404 | }, 1405 | { 1406 | "cell_type": "code", 1407 | "source": [ 1408 | "def get_full_name(name, surname):\n", 1409 | " return name + \" \" + surname" 1410 | ], 1411 | "metadata": { 1412 | "id": "tyYDQWjsqVIt" 1413 | }, 1414 | "execution_count": null, 1415 | "outputs": [] 1416 | }, 1417 | { 1418 | "cell_type": "code", 1419 | "source": [ 1420 | "name = \"kaan\"\n", 1421 | "surname = \"ozbudak\"\n", 1422 | "full_name = get_full_name(name, surname)\n", 1423 | "print(full_name)" 1424 | ], 1425 | "metadata": { 1426 | "colab": { 1427 | "base_uri": "https://localhost:8080/" 1428 | }, 1429 | "id": "SYW5zd_9qcf2", 1430 | "outputId": "6676a624-724b-41f5-b8c5-3cf532257a63" 1431 | }, 1432 | "execution_count": null, 1433 | "outputs": [ 1434 | { 1435 | "output_type": "stream", 1436 | "name": "stdout", 1437 | "text": [ 1438 | "kaan ozbudak\n" 1439 | ] 1440 | } 1441 | ] 1442 | }, 1443 | { 1444 | "cell_type": "code", 1445 | "source": [ 1446 | "names = [\"kaan\", \"eray\", \"batu\"]\n", 1447 | "surnames = [\"ozbudak\", \"surmeli\", \"kargili\"]\n", 1448 | "\n", 1449 | "for i in range(len(names)):\n", 1450 | " print(i)\n", 1451 | " print(names[i])\n", 1452 | " print(surnames[i])\n", 1453 | " full_name = get_full_name(names[i], surnames[i])\n", 1454 | " print(f\"full name is {full_name}\")" 1455 | ], 1456 | "metadata": { 1457 | "colab": { 1458 | "base_uri": "https://localhost:8080/" 1459 | }, 1460 | "id": "Ek8PuadVqj5d", 1461 | "outputId": "673ecb18-5d36-465f-f5c3-263d64d92b29" 1462 | }, 1463 | "execution_count": null, 1464 | "outputs": [ 1465 | { 1466 | "output_type": "stream", 1467 | "name": "stdout", 1468 | "text": [ 1469 | "0\n", 1470 | "kaan\n", 1471 | "ozbudak\n", 1472 | "full name is kaan ozbudak\n", 1473 | "1\n", 1474 | "eray\n", 1475 | "surmeli\n", 1476 | "full name is eray surmeli\n", 1477 | "2\n", 1478 | "batu\n", 1479 | "kargili\n", 1480 | "full name is batu kargili\n" 1481 | ] 1482 | } 1483 | ] 1484 | }, 1485 | { 1486 | "cell_type": "markdown", 1487 | "source": [ 1488 | "# Exceptions\n", 1489 | "- Programmer Errors\n", 1490 | "- Program Bugs\n", 1491 | "- Exceptions" 1492 | ], 1493 | "metadata": { 1494 | "id": "I7j5P9pssw2W" 1495 | } 1496 | }, 1497 | { 1498 | "cell_type": "code", 1499 | "source": [ 1500 | "print(0/0)" 1501 | ], 1502 | "metadata": { 1503 | "colab": { 1504 | "base_uri": "https://localhost:8080/", 1505 | "height": 166 1506 | }, 1507 | "id": "pYVwsk0GsxK3", 1508 | "outputId": "c719b9dc-c6db-4cd0-a931-850e31af646f" 1509 | }, 1510 | "execution_count": 69, 1511 | "outputs": [ 1512 | { 1513 | "output_type": "error", 1514 | "ename": "ZeroDivisionError", 1515 | "evalue": "ignored", 1516 | "traceback": [ 1517 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 1518 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 1519 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\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", 1520 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 1521 | ] 1522 | } 1523 | ] 1524 | }, 1525 | { 1526 | "cell_type": "code", 1527 | "source": [ 1528 | "print(10/\"kaan\")" 1529 | ], 1530 | "metadata": { 1531 | "colab": { 1532 | "base_uri": "https://localhost:8080/", 1533 | "height": 166 1534 | }, 1535 | "id": "jJDmRdD_sz_F", 1536 | "outputId": "1c712d66-2c06-4635-8316-1a4d78c513bc" 1537 | }, 1538 | "execution_count": 70, 1539 | "outputs": [ 1540 | { 1541 | "output_type": "error", 1542 | "ename": "TypeError", 1543 | "evalue": "ignored", 1544 | "traceback": [ 1545 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 1546 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 1547 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m\"kaan.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 1548 | "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'int' and 'str'" 1549 | ] 1550 | } 1551 | ] 1552 | }, 1553 | { 1554 | "cell_type": "code", 1555 | "source": [ 1556 | "num=\"5\"\n", 1557 | "print(10/num) " 1558 | ], 1559 | "metadata": { 1560 | "colab": { 1561 | "base_uri": "https://localhost:8080/", 1562 | "height": 166 1563 | }, 1564 | "id": "zvcR3YsCs2ua", 1565 | "outputId": "6d70474f-1714-4000-8a1c-9b339930754d" 1566 | }, 1567 | "execution_count": 71, 1568 | "outputs": [ 1569 | { 1570 | "output_type": "error", 1571 | "ename": "TypeError", 1572 | "evalue": "ignored", 1573 | "traceback": [ 1574 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 1575 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 1576 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m\"5\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 1577 | "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'int' and 'str'" 1578 | ] 1579 | } 1580 | ] 1581 | }, 1582 | { 1583 | "cell_type": "code", 1584 | "source": [ 1585 | "try:\n", 1586 | " num=\"5\"\n", 1587 | " print(10/num)\n", 1588 | "except Exception as ex:\n", 1589 | " print(\"You can not divide int by str\")" 1590 | ], 1591 | "metadata": { 1592 | "colab": { 1593 | "base_uri": "https://localhost:8080/" 1594 | }, 1595 | "id": "xohbcrLatNH0", 1596 | "outputId": "7c832489-3170-480d-d311-b3561979c67a" 1597 | }, 1598 | "execution_count": 74, 1599 | "outputs": [ 1600 | { 1601 | "output_type": "stream", 1602 | "name": "stdout", 1603 | "text": [ 1604 | "You can not divide int by str\n" 1605 | ] 1606 | } 1607 | ] 1608 | }, 1609 | { 1610 | "cell_type": "code", 1611 | "source": [ 1612 | "try:\n", 1613 | " num=\"5\"\n", 1614 | " print(10/num)\n", 1615 | "except Exception as ex:\n", 1616 | " num = int(num)\n", 1617 | " print(10/num)" 1618 | ], 1619 | "metadata": { 1620 | "colab": { 1621 | "base_uri": "https://localhost:8080/" 1622 | }, 1623 | "id": "8Z4RLi0EtNZ8", 1624 | "outputId": "5e5cb2ba-02d1-43b7-a9c5-70cb25734250" 1625 | }, 1626 | "execution_count": 75, 1627 | "outputs": [ 1628 | { 1629 | "output_type": "stream", 1630 | "name": "stdout", 1631 | "text": [ 1632 | "2.0\n" 1633 | ] 1634 | } 1635 | ] 1636 | }, 1637 | { 1638 | "cell_type": "markdown", 1639 | "source": [ 1640 | "" 1641 | ], 1642 | "metadata": { 1643 | "id": "UxOcdqCpwj0H" 1644 | } 1645 | } 1646 | ] 1647 | } --------------------------------------------------------------------------------