├── basics ├── print-1.py ├── type.py ├── concat.py ├── typecasting.py ├── input.py ├── print-3.py ├── comment.py ├── print-2.py ├── variable.py ├── import-1.ipynb ├── import-2.ipynb ├── import-3.ipynb ├── print-4.ipynb ├── operator.ipynb ├── variable-value-assignment.ipynb └── variable-naming.ipynb ├── images └── python.jpg ├── .github └── workflows │ └── contributor.yml ├── string ├── len.ipynb ├── check-string.ipynb ├── access-by-char.ipynb └── slicing.ipynb ├── oop ├── inheritance.ipynb ├── encapsulation.ipynb ├── polymorphism.ipynb ├── constructor.ipynb └── class-object.ipynb ├── control-structure ├── bool-return.ipynb ├── problem-1.ipynb ├── jump-statement.ipynb ├── if-else.ipynb ├── pattern.ipynb ├── while-loop.ipynb └── for-loop.ipynb ├── data-structure ├── dictionary.ipynb ├── set.ipynb ├── tuple.ipynb └── list.ipynb ├── function ├── lambda-function.ipynb └── user-defined-function.ipynb └── README.md /basics/print-1.py: -------------------------------------------------------------------------------- 1 | print("Hello") 2 | print('Bye') 3 | print('''Good''') 4 | print(12) 5 | -------------------------------------------------------------------------------- /images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvikAgarwala/Python-Binary-Coders/HEAD/images/python.jpg -------------------------------------------------------------------------------- /basics/type.py: -------------------------------------------------------------------------------- 1 | x = 5 # integer 2 | y = 5.43 # float 3 | z = "BCD_123@" # string 4 | b = True # boolean 5 | 6 | # print the type of variable 7 | print(type(x)) 8 | print(type(y)) 9 | print(type(z)) 10 | print(type(b)) -------------------------------------------------------------------------------- /basics/concat.py: -------------------------------------------------------------------------------- 1 | str1 = "Good" 2 | str2 = "Bye" 3 | 4 | print(str1 + str2) 5 | print(str1 + " " + str2) 6 | ''' more ways to do the same 7 | 8 | print(str1 + ' ' + str2) 9 | print(str1 + ''' ''' + str2) 10 | 11 | ''' 12 | -------------------------------------------------------------------------------- /basics/typecasting.py: -------------------------------------------------------------------------------- 1 | x = 5 2 | y = float(x) # typecasting is applied 3 | 4 | print(type(x)) # datatype of x is unchanged 5 | print(type(y)) 6 | 7 | print(x) 8 | print(y) 9 | 10 | m = 3.67 11 | z = int(m) # typecasting is applied 12 | 13 | print(z) 14 | -------------------------------------------------------------------------------- /basics/input.py: -------------------------------------------------------------------------------- 1 | # print("Enter a number:") 2 | # x = input() 3 | # x = int(x) 4 | x = int(input("Enter a number:")) # taking input and typecasting to int as by default the input function takes input in the form of STRING 5 | 6 | print(type(x)) # int 7 | print(x + 2) 8 | -------------------------------------------------------------------------------- /basics/print-3.py: -------------------------------------------------------------------------------- 1 | print("I am\nAvik") # \n means new line 2 | 3 | print("Python is ", end = "") # default line break is no more 4 | print("FUN") 5 | 6 | print("Python is", end = " ") 7 | print("FUN") 8 | 9 | print("Python is ", end = "SUPER ") 10 | print("FUN") 11 | -------------------------------------------------------------------------------- /basics/comment.py: -------------------------------------------------------------------------------- 1 | # example of comments 2 | 3 | print("Hello") # it prints in the console 4 | print('Bye') 5 | 6 | ''' 7 | Hey 8 | It's a comment 9 | ''' 10 | 11 | # triple quotes provide support for multiline 12 | print('''Good 13 | Boy 14 | Girl''') 15 | 16 | print(12) 17 | -------------------------------------------------------------------------------- /basics/print-2.py: -------------------------------------------------------------------------------- 1 | x = 404 # int 2 | 3 | print("Value of x is " + str(x)) 4 | # in case of comma, type doesn't matter 5 | print("Value of x is", x) # by deafult a blank space in between 6 | # f string 7 | print(f"Value of x is {x}") # variable inside ' { } ' gets replaced with its value 8 | -------------------------------------------------------------------------------- /basics/variable.py: -------------------------------------------------------------------------------- 1 | x = 5 # integer 2 | y = 5.43 # floating point number (float) 3 | z = "BCD_123@" # string 4 | m = 'T' # string 5 | b = True # boolean 6 | f = False # boolean 7 | 8 | print(x, y, z, m, b, f) 9 | 10 | m = 12 # this will override the previous value of m 11 | 12 | print(m) 13 | -------------------------------------------------------------------------------- /.github/workflows/contributor.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | workflow_dispatch: 6 | 7 | jobs: 8 | contrib-readme-job: 9 | runs-on: ubuntu-latest 10 | name: A job to automate contrib in readme 11 | steps: 12 | - name: Contribute List 13 | uses: akhilmhdh/contributors-readme-action@v2.3.6 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | -------------------------------------------------------------------------------- /string/len.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "5\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "str = \"Hello\"\n", 18 | "print(len(str)) # len() returns the length of the string" 19 | ] 20 | } 21 | ], 22 | "metadata": { 23 | "kernelspec": { 24 | "display_name": "Python 3", 25 | "language": "python", 26 | "name": "python3" 27 | }, 28 | "language_info": { 29 | "codemirror_mode": { 30 | "name": "ipython", 31 | "version": 3 32 | }, 33 | "file_extension": ".py", 34 | "mimetype": "text/x-python", 35 | "name": "python", 36 | "nbconvert_exporter": "python", 37 | "pygments_lexer": "ipython3", 38 | "version": "3.11.4" 39 | }, 40 | "orig_nbformat": 4 41 | }, 42 | "nbformat": 4, 43 | "nbformat_minor": 2 44 | } 45 | -------------------------------------------------------------------------------- /basics/import-1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "4.0" 12 | ] 13 | }, 14 | "execution_count": 2, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "import math\n", 21 | "math.sqrt(16)" 22 | ] 23 | } 24 | ], 25 | "metadata": { 26 | "kernelspec": { 27 | "display_name": "Python 3", 28 | "language": "python", 29 | "name": "python3" 30 | }, 31 | "language_info": { 32 | "codemirror_mode": { 33 | "name": "ipython", 34 | "version": 3 35 | }, 36 | "file_extension": ".py", 37 | "mimetype": "text/x-python", 38 | "name": "python", 39 | "nbconvert_exporter": "python", 40 | "pygments_lexer": "ipython3", 41 | "version": "3.11.4" 42 | }, 43 | "orig_nbformat": 4 44 | }, 45 | "nbformat": 4, 46 | "nbformat_minor": 2 47 | } 48 | -------------------------------------------------------------------------------- /basics/import-2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "2.0" 12 | ] 13 | }, 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "from math import sqrt\n", 21 | "sqrt(4)" 22 | ] 23 | } 24 | ], 25 | "metadata": { 26 | "kernelspec": { 27 | "display_name": "Python 3", 28 | "language": "python", 29 | "name": "python3" 30 | }, 31 | "language_info": { 32 | "codemirror_mode": { 33 | "name": "ipython", 34 | "version": 3 35 | }, 36 | "file_extension": ".py", 37 | "mimetype": "text/x-python", 38 | "name": "python", 39 | "nbconvert_exporter": "python", 40 | "pygments_lexer": "ipython3", 41 | "version": "3.11.4" 42 | }, 43 | "orig_nbformat": 4 44 | }, 45 | "nbformat": 4, 46 | "nbformat_minor": 2 47 | } 48 | -------------------------------------------------------------------------------- /oop/inheritance.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Avik 18\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "class A: # parent\n", 18 | " name = \"Avik\"\n", 19 | "\n", 20 | "class B(A): # child\n", 21 | " age = 18\n", 22 | "\n", 23 | "obj = B()\n", 24 | "print(obj.name, obj.age)" 25 | ] 26 | } 27 | ], 28 | "metadata": { 29 | "kernelspec": { 30 | "display_name": "Python 3", 31 | "language": "python", 32 | "name": "python3" 33 | }, 34 | "language_info": { 35 | "codemirror_mode": { 36 | "name": "ipython", 37 | "version": 3 38 | }, 39 | "file_extension": ".py", 40 | "mimetype": "text/x-python", 41 | "name": "python", 42 | "nbconvert_exporter": "python", 43 | "pygments_lexer": "ipython3", 44 | "version": "3.11.4" 45 | }, 46 | "orig_nbformat": 4 47 | }, 48 | "nbformat": 4, 49 | "nbformat_minor": 2 50 | } 51 | -------------------------------------------------------------------------------- /control-structure/bool-return.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "a = 5\n", 10 | "b = 7" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "True\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "print(a < b)" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 3, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "False\n" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "print(a > b)" 45 | ] 46 | } 47 | ], 48 | "metadata": { 49 | "kernelspec": { 50 | "display_name": "Python 3", 51 | "language": "python", 52 | "name": "python3" 53 | }, 54 | "language_info": { 55 | "codemirror_mode": { 56 | "name": "ipython", 57 | "version": 3 58 | }, 59 | "file_extension": ".py", 60 | "mimetype": "text/x-python", 61 | "name": "python", 62 | "nbconvert_exporter": "python", 63 | "pygments_lexer": "ipython3", 64 | "version": "3.11.4" 65 | }, 66 | "orig_nbformat": 4 67 | }, 68 | "nbformat": 4, 69 | "nbformat_minor": 2 70 | } 71 | -------------------------------------------------------------------------------- /control-structure/problem-1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "a = 5\n", 10 | "b = 3\n", 11 | "c = 2" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 6, 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "A is greatest\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "if a > b:\n", 29 | " if a > c:\n", 30 | " print(\"A is greatest\")\n", 31 | " else:\n", 32 | " print(\"C is greatest\")\n", 33 | "else:\n", 34 | " if b > c:\n", 35 | " print(\"B is greatest\")\n", 36 | " else:\n", 37 | " print(\"C is greatest\")\n", 38 | "\n", 39 | " " 40 | ] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 3", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.11.4" 60 | }, 61 | "orig_nbformat": 4 62 | }, 63 | "nbformat": 4, 64 | "nbformat_minor": 2 65 | } 66 | -------------------------------------------------------------------------------- /control-structure/jump-statement.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "1\n", 13 | "2\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "i = 1\n", 19 | "while i <= 3:\n", 20 | " print(i)\n", 21 | " if i == 2:\n", 22 | " break # terminates the loop\n", 23 | " i += 1" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 5, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "1\n", 36 | "3\n" 37 | ] 38 | } 39 | ], 40 | "source": [ 41 | "i = 1\n", 42 | "while i <= 3:\n", 43 | " if i == 2:\n", 44 | " i += 1\n", 45 | " continue # skips the current iteration\n", 46 | " print(i)\n", 47 | " i += 1" 48 | ] 49 | } 50 | ], 51 | "metadata": { 52 | "kernelspec": { 53 | "display_name": "Python 3", 54 | "language": "python", 55 | "name": "python3" 56 | }, 57 | "language_info": { 58 | "codemirror_mode": { 59 | "name": "ipython", 60 | "version": 3 61 | }, 62 | "file_extension": ".py", 63 | "mimetype": "text/x-python", 64 | "name": "python", 65 | "nbconvert_exporter": "python", 66 | "pygments_lexer": "ipython3", 67 | "version": "3.11.4" 68 | }, 69 | "orig_nbformat": 4 70 | }, 71 | "nbformat": 4, 72 | "nbformat_minor": 2 73 | } 74 | -------------------------------------------------------------------------------- /basics/import-3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 3, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "4.0" 12 | ] 13 | }, 14 | "execution_count": 3, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "import math as m\n", 21 | "m.sqrt(16)" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 4, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "ename": "NameError", 31 | "evalue": "name 'math' is not defined", 32 | "output_type": "error", 33 | "traceback": [ 34 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 35 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 36 | "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m math\u001b[39m.\u001b[39msqrt(\u001b[39m16\u001b[39m) \u001b[39m# error\u001b[39;00m\n", 37 | "\u001b[1;31mNameError\u001b[0m: name 'math' is not defined" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "math.sqrt(16) # error" 43 | ] 44 | } 45 | ], 46 | "metadata": { 47 | "kernelspec": { 48 | "display_name": "Python 3", 49 | "language": "python", 50 | "name": "python3" 51 | }, 52 | "language_info": { 53 | "codemirror_mode": { 54 | "name": "ipython", 55 | "version": 3 56 | }, 57 | "file_extension": ".py", 58 | "mimetype": "text/x-python", 59 | "name": "python", 60 | "nbconvert_exporter": "python", 61 | "pygments_lexer": "ipython3", 62 | "version": "3.11.4" 63 | }, 64 | "orig_nbformat": 4 65 | }, 66 | "nbformat": 4, 67 | "nbformat_minor": 2 68 | } 69 | -------------------------------------------------------------------------------- /oop/encapsulation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 9, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "abc\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "class User:\n", 18 | " __username = 'markopolo'\n", 19 | " __password = 'abc'\n", 20 | "\n", 21 | " def get_credentials(self):\n", 22 | " passkey = input(\"Enter passkey to view credentials : \")\n", 23 | " if passkey == \"123\":\n", 24 | " print(self.__password)\n", 25 | " else:\n", 26 | " print(\"Wrong passkey!\")\n", 27 | "\n", 28 | "\n", 29 | "u = User()\n", 30 | "u.get_credentials()" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 16, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "Hello\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "class Test:\n", 48 | "\n", 49 | " def __pvt_method(self):\n", 50 | " print(\"Hello\")\n", 51 | "\n", 52 | " def test(self):\n", 53 | " self.__pvt_method()\n", 54 | "\n", 55 | "u = Test()\n", 56 | "u.test()" 57 | ] 58 | } 59 | ], 60 | "metadata": { 61 | "kernelspec": { 62 | "display_name": "Python 3", 63 | "language": "python", 64 | "name": "python3" 65 | }, 66 | "language_info": { 67 | "codemirror_mode": { 68 | "name": "ipython", 69 | "version": 3 70 | }, 71 | "file_extension": ".py", 72 | "mimetype": "text/x-python", 73 | "name": "python", 74 | "nbconvert_exporter": "python", 75 | "pygments_lexer": "ipython3", 76 | "version": "3.11.4" 77 | }, 78 | "orig_nbformat": 4 79 | }, 80 | "nbformat": 4, 81 | "nbformat_minor": 2 82 | } 83 | -------------------------------------------------------------------------------- /control-structure/if-else.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "a = 5\n", 10 | "b = 3" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "A is greater\n", 23 | "Hello\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "if a > b:\n", 29 | " print(\"A is greater\")\n", 30 | " print(\"Hello\")\n", 31 | "else: # if the 'if' block becomes false\n", 32 | " print(\"B is greater\")\n", 33 | " print(\"Bye\")" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 3, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "c = 3\n", 43 | "d = 5" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 4, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "D is greater\n", 56 | "Bye\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "if c > d:\n", 62 | " print(\"C is greater\")\n", 63 | " print(\"Hello\")\n", 64 | "else:\n", 65 | " print(\"D is greater\")\n", 66 | " print(\"Bye\")" 67 | ] 68 | } 69 | ], 70 | "metadata": { 71 | "kernelspec": { 72 | "display_name": "Python 3", 73 | "language": "python", 74 | "name": "python3" 75 | }, 76 | "language_info": { 77 | "codemirror_mode": { 78 | "name": "ipython", 79 | "version": 3 80 | }, 81 | "file_extension": ".py", 82 | "mimetype": "text/x-python", 83 | "name": "python", 84 | "nbconvert_exporter": "python", 85 | "pygments_lexer": "ipython3", 86 | "version": "3.11.4" 87 | }, 88 | "orig_nbformat": 4 89 | }, 90 | "nbformat": 4, 91 | "nbformat_minor": 2 92 | } 93 | -------------------------------------------------------------------------------- /string/check-string.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "True\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "str = \"This is a string\"\n", 18 | "print(\"is\" in str) # returns True if present" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "False\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "print(\"BCD\" in str)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 3, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "True\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "my_string = \"This is a sample string\"\n", 53 | "print(\"super\" not in my_string)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 4, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "False\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "print(\"sample\" not in my_string)" 71 | ] 72 | } 73 | ], 74 | "metadata": { 75 | "kernelspec": { 76 | "display_name": "Python 3", 77 | "language": "python", 78 | "name": "python3" 79 | }, 80 | "language_info": { 81 | "codemirror_mode": { 82 | "name": "ipython", 83 | "version": 3 84 | }, 85 | "file_extension": ".py", 86 | "mimetype": "text/x-python", 87 | "name": "python", 88 | "nbconvert_exporter": "python", 89 | "pygments_lexer": "ipython3", 90 | "version": "3.11.4" 91 | }, 92 | "orig_nbformat": 4 93 | }, 94 | "nbformat": 4, 95 | "nbformat_minor": 2 96 | } 97 | -------------------------------------------------------------------------------- /basics/print-4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "5\n", 13 | "6\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "x = 5\n", 19 | "y = 6\n", 20 | "\n", 21 | "# we can display using print()\n", 22 | "print(x)\n", 23 | "print(y)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 13, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "5\n" 36 | ] 37 | }, 38 | { 39 | "data": { 40 | "text/plain": [ 41 | "6" 42 | ] 43 | }, 44 | "execution_count": 13, 45 | "metadata": {}, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "'''\n", 51 | "in interactive mode (REPL),\n", 52 | "expression in last line\n", 53 | "gets printed automatically\n", 54 | "'''\n", 55 | "print(x)\n", 56 | "y" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 6, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "6" 68 | ] 69 | }, 70 | "execution_count": 6, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "x # will not be printed as not in last line\n", 77 | "y" 78 | ] 79 | } 80 | ], 81 | "metadata": { 82 | "kernelspec": { 83 | "display_name": "Python 3", 84 | "language": "python", 85 | "name": "python3" 86 | }, 87 | "language_info": { 88 | "codemirror_mode": { 89 | "name": "ipython", 90 | "version": 3 91 | }, 92 | "file_extension": ".py", 93 | "mimetype": "text/x-python", 94 | "name": "python", 95 | "nbconvert_exporter": "python", 96 | "pygments_lexer": "ipython3", 97 | "version": "3.11.4" 98 | }, 99 | "orig_nbformat": 4 100 | }, 101 | "nbformat": 4, 102 | "nbformat_minor": 2 103 | } 104 | -------------------------------------------------------------------------------- /string/access-by-char.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "A\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "str = \"Alik\"\n", 18 | "print(str[0]) # prints character of index 0" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "l\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "print(str[1]) # prints character of index 1" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 3, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "k\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "print(str[3]) # prints character of index 3" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "ename": "IndexError", 62 | "evalue": "string index out of range", 63 | "output_type": "error", 64 | "traceback": [ 65 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 66 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 67 | "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mstr\u001b[39;49m[\u001b[39m4\u001b[39;49m])\n", 68 | "\u001b[1;31mIndexError\u001b[0m: string index out of range" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "print(str[4]) # index out of bound" 74 | ] 75 | } 76 | ], 77 | "metadata": { 78 | "kernelspec": { 79 | "display_name": "Python 3", 80 | "language": "python", 81 | "name": "python3" 82 | }, 83 | "language_info": { 84 | "codemirror_mode": { 85 | "name": "ipython", 86 | "version": 3 87 | }, 88 | "file_extension": ".py", 89 | "mimetype": "text/x-python", 90 | "name": "python", 91 | "nbconvert_exporter": "python", 92 | "pygments_lexer": "ipython3", 93 | "version": "3.11.4" 94 | }, 95 | "orig_nbformat": 4 96 | }, 97 | "nbformat": 4, 98 | "nbformat_minor": 2 99 | } 100 | -------------------------------------------------------------------------------- /control-structure/pattern.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "*****\n", 13 | "*****\n", 14 | "*****\n", 15 | "*****\n", 16 | "*****\n", 17 | "*****\n" 18 | ] 19 | } 20 | ], 21 | "source": [ 22 | "row = int(input(\"Enter the row number: \"))\n", 23 | "for i in range(1, row + 1):\n", 24 | " print('*' * 5) # prints '*' 5 times" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 2, 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "name": "stdout", 34 | "output_type": "stream", 35 | "text": [ 36 | "* * * * * \n", 37 | "* * * * * \n", 38 | "* * * * * \n", 39 | "* * * * * \n", 40 | "* * * * * \n", 41 | "* * * * * \n", 42 | "* * * * * \n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "#alternative way\n", 48 | "row = int(input(\"Enter the row number: \"))\n", 49 | "for i in range(1, row + 1): # for row\n", 50 | " for j in range(1, 6): # for col\n", 51 | " print('*', end=\" \")\n", 52 | " print() # new line" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "1 \n", 65 | "1 2 \n", 66 | "1 2 3 \n", 67 | "1 2 3 4 \n", 68 | "1 2 3 4 5 \n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "# 1\n", 74 | "# 1 2\n", 75 | "# 1 2 3\n", 76 | "# 1 2 3 4\n", 77 | "# 1 2 3 4 5\n", 78 | "\n", 79 | "row = int(input(\"Enter the row number: \"))\n", 80 | "for i in range(1, row + 1): # row\n", 81 | " for j in range(1, i + 1): # col\n", 82 | " print(j, end=\" \")\n", 83 | " print() # new line" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "language": "python", 91 | "name": "python3" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.11.4" 104 | }, 105 | "orig_nbformat": 4 106 | }, 107 | "nbformat": 4, 108 | "nbformat_minor": 2 109 | } 110 | -------------------------------------------------------------------------------- /data-structure/dictionary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 12, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "{12: 'Avik', 75: 'Alik', 49: 'Pritam'}\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "student = {12 : \"Avik\", 75 : \"Alik\", 49 : \"Pritam\"}\n", 18 | "print(student)" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 13, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "Pritam\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "print(student[49])" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 15, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "'Ankika'" 47 | ] 48 | }, 49 | "execution_count": 15, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "student[75] = \"Ankika\"\n", 56 | "student[75]" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 22, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "'Avik'" 68 | ] 69 | }, 70 | "execution_count": 22, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "d = {12 : \"Avik\", True : 49}\n", 77 | "student[True]" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 23, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "data": { 87 | "text/plain": [ 88 | "'Avik'" 89 | ] 90 | }, 91 | "execution_count": 23, 92 | "metadata": {}, 93 | "output_type": "execute_result" 94 | } 95 | ], 96 | "source": [ 97 | "d.get(12)" 98 | ] 99 | } 100 | ], 101 | "metadata": { 102 | "kernelspec": { 103 | "display_name": "Python 3", 104 | "language": "python", 105 | "name": "python3" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": { 109 | "name": "ipython", 110 | "version": 3 111 | }, 112 | "file_extension": ".py", 113 | "mimetype": "text/x-python", 114 | "name": "python", 115 | "nbconvert_exporter": "python", 116 | "pygments_lexer": "ipython3", 117 | "version": "3.11.4" 118 | }, 119 | "orig_nbformat": 4 120 | }, 121 | "nbformat": 4, 122 | "nbformat_minor": 2 123 | } 124 | -------------------------------------------------------------------------------- /oop/polymorphism.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "4" 12 | ] 13 | }, 14 | "execution_count": 2, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "len(\"Avik\") # length of string" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 4, 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "data": { 30 | "text/plain": [ 31 | "4" 32 | ] 33 | }, 34 | "execution_count": 4, 35 | "metadata": {}, 36 | "output_type": "execute_result" 37 | } 38 | ], 39 | "source": [ 40 | "l = [1, 4, 6, \"Avik\"]\n", 41 | "len(l) # element count" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 11, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "7\n", 54 | "12\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "# overloading\n", 60 | "\n", 61 | "def sum(a, b):\n", 62 | " print(a + b)\n", 63 | "\n", 64 | "sum(1, 6)\n", 65 | "\n", 66 | "def sum(a, b, c):\n", 67 | " print(a + b + c)\n", 68 | "\n", 69 | "sum(1, 6, 5)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 2, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "Hello\n", 82 | "Bye\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "# override\n", 88 | "\n", 89 | "class A:\n", 90 | " def func():\n", 91 | " print(\"Hello\")\n", 92 | "\n", 93 | "class B(A):\n", 94 | " def func():\n", 95 | " print(\"Bye\")\n", 96 | "\n", 97 | "\n", 98 | "A.func()\n", 99 | "B.func()" 100 | ] 101 | } 102 | ], 103 | "metadata": { 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.11.4" 120 | }, 121 | "orig_nbformat": 4 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 2 125 | } 126 | -------------------------------------------------------------------------------- /function/lambda-function.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 25, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Hello Avik\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "# def greet(name):\n", 18 | "# print(\"Hello\", name)\n", 19 | "\n", 20 | "\n", 21 | "greet = lambda name : print(\"Hello\", name)\n", 22 | "\n", 23 | "# main\n", 24 | "greet(\"Avik\")" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 26, 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "name": "stdout", 34 | "output_type": "stream", 35 | "text": [ 36 | "Hello\n" 37 | ] 38 | } 39 | ], 40 | "source": [ 41 | "# def greet():\n", 42 | "# print(\"Hello\")\n", 43 | "\n", 44 | "\n", 45 | "greet = lambda : print(\"Hello\") # lambda without argument(s)\n", 46 | "\n", 47 | "# main\n", 48 | "greet()" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 27, 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "data": { 58 | "text/plain": [ 59 | "11" 60 | ] 61 | }, 62 | "execution_count": 27, 63 | "metadata": {}, 64 | "output_type": "execute_result" 65 | } 66 | ], 67 | "source": [ 68 | "sum = lambda a, b : a + b\n", 69 | "\n", 70 | "sum(5, 6)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 31, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "7" 82 | ] 83 | }, 84 | "execution_count": 31, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "def func(x):\n", 91 | " return lambda y : y + x\n", 92 | "\n", 93 | "\n", 94 | "# main\n", 95 | "plus_two = func(2)\n", 96 | "\n", 97 | "plus_two(5)" 98 | ] 99 | } 100 | ], 101 | "metadata": { 102 | "kernelspec": { 103 | "display_name": "Python 3", 104 | "language": "python", 105 | "name": "python3" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": { 109 | "name": "ipython", 110 | "version": 3 111 | }, 112 | "file_extension": ".py", 113 | "mimetype": "text/x-python", 114 | "name": "python", 115 | "nbconvert_exporter": "python", 116 | "pygments_lexer": "ipython3", 117 | "version": "3.11.4" 118 | }, 119 | "orig_nbformat": 4 120 | }, 121 | "nbformat": 4, 122 | "nbformat_minor": 2 123 | } 124 | -------------------------------------------------------------------------------- /string/slicing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "inar\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "str = \"Binary Coders\"\n", 18 | "print(str[1:5]) # index 1 to 4" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 6, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "Binar\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "print(str[:5]) # slice from first" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 9, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "inary Coders\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "print(str[1:]) # slice to the last" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 11, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "Binary Coders\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "print(str[:]) # slicing full string" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 14, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "ica\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "new_string = \"duplicate\"\n", 87 | "print(new_string[-5:-2]) # negative indexing" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 16, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "print(new_string[-2:-5]) # no print" 105 | ] 106 | } 107 | ], 108 | "metadata": { 109 | "kernelspec": { 110 | "display_name": "Python 3", 111 | "language": "python", 112 | "name": "python3" 113 | }, 114 | "language_info": { 115 | "codemirror_mode": { 116 | "name": "ipython", 117 | "version": 3 118 | }, 119 | "file_extension": ".py", 120 | "mimetype": "text/x-python", 121 | "name": "python", 122 | "nbconvert_exporter": "python", 123 | "pygments_lexer": "ipython3", 124 | "version": "3.11.4" 125 | }, 126 | "orig_nbformat": 4 127 | }, 128 | "nbformat": 4, 129 | "nbformat_minor": 2 130 | } 131 | -------------------------------------------------------------------------------- /data-structure/set.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "{12, 65, 78, 89, 100}" 12 | ] 13 | }, 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "s = {12, 65, 89, 12, 65, 78, 100}\n", 21 | "s # print(s)" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 3, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "ename": "TypeError", 31 | "evalue": "'set' object is not subscriptable", 32 | "output_type": "error", 33 | "traceback": [ 34 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 35 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 36 | "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m s[\u001b[39m2\u001b[39;49m] \u001b[39m# error as set is unordered\u001b[39;00m\n", 37 | "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "s[2] # error as set is unordered" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 9, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "{1, 6, 8}" 54 | ] 55 | }, 56 | "execution_count": 9, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "s = {1, 4, 6, 8}\n", 63 | "s.remove(4)\n", 64 | "s" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 10, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "data": { 74 | "text/plain": [ 75 | "{1, 4, 6, 10}" 76 | ] 77 | }, 78 | "execution_count": 10, 79 | "metadata": {}, 80 | "output_type": "execute_result" 81 | } 82 | ], 83 | "source": [ 84 | "s = {1, 4, 6}\n", 85 | "s.add(10)\n", 86 | "s" 87 | ] 88 | } 89 | ], 90 | "metadata": { 91 | "kernelspec": { 92 | "display_name": "Python 3", 93 | "language": "python", 94 | "name": "python3" 95 | }, 96 | "language_info": { 97 | "codemirror_mode": { 98 | "name": "ipython", 99 | "version": 3 100 | }, 101 | "file_extension": ".py", 102 | "mimetype": "text/x-python", 103 | "name": "python", 104 | "nbconvert_exporter": "python", 105 | "pygments_lexer": "ipython3", 106 | "version": "3.11.4" 107 | }, 108 | "orig_nbformat": 4 109 | }, 110 | "nbformat": 4, 111 | "nbformat_minor": 2 112 | } 113 | -------------------------------------------------------------------------------- /oop/constructor.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 7, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Avik 20\n", 13 | "Sayantana 18\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "# without constructor\n", 19 | "\n", 20 | "class Human:\n", 21 | " def set_details(self, x, y):\n", 22 | " self.name = x\n", 23 | " self.age = y\n", 24 | "\n", 25 | "h1 = Human()\n", 26 | "h1.set_details(\"Avik\", 20)\n", 27 | "\n", 28 | "h2 = Human()\n", 29 | "h2.set_details(\"Sayantana\", 18)\n", 30 | "\n", 31 | "print(h1.name, h1.age)\n", 32 | "print(h2.name, h2.age)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 32, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "Constructor has been called!\n", 45 | "Constructor has been called!\n", 46 | "Constructor has been called!\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "class Human:\n", 52 | " def __init__(self): # called when object is created\n", 53 | " print(\"Constructor has been called!\")\n", 54 | "\n", 55 | "h1 = Human()\n", 56 | "h2 = Human()\n", 57 | "\n", 58 | "# alternative way\n", 59 | "h3 = None\n", 60 | "Human.__init__(h3)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 28, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "Avik 20\n", 73 | "Priyam 17\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "class Human:\n", 79 | " def __init__(self, name, age): # called when object is created\n", 80 | " self.name = name\n", 81 | " self.age = age\n", 82 | " '''\n", 83 | " self.name --> name is class variable\n", 84 | " name --> name is local variable passed to method\n", 85 | " '''\n", 86 | "\n", 87 | "# create object\n", 88 | "h1 = Human(\"Avik\", 20)\n", 89 | "# alternative way\n", 90 | "Human.__init__(h2, \"Priyam\", 17)\n", 91 | "\n", 92 | "print(h1.name, h1.age)\n", 93 | "print(h2.name, h2.age)\n" 94 | ] 95 | } 96 | ], 97 | "metadata": { 98 | "kernelspec": { 99 | "display_name": "Python 3", 100 | "language": "python", 101 | "name": "python3" 102 | }, 103 | "language_info": { 104 | "codemirror_mode": { 105 | "name": "ipython", 106 | "version": 3 107 | }, 108 | "file_extension": ".py", 109 | "mimetype": "text/x-python", 110 | "name": "python", 111 | "nbconvert_exporter": "python", 112 | "pygments_lexer": "ipython3", 113 | "version": "3.11.4" 114 | }, 115 | "orig_nbformat": 4 116 | }, 117 | "nbformat": 4, 118 | "nbformat_minor": 2 119 | } 120 | -------------------------------------------------------------------------------- /basics/operator.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "a = 5\n", 10 | "b = 3" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "data": { 20 | "text/plain": [ 21 | "8" 22 | ] 23 | }, 24 | "execution_count": 2, 25 | "metadata": {}, 26 | "output_type": "execute_result" 27 | } 28 | ], 29 | "source": [ 30 | "a + b" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 3, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/plain": [ 41 | "2" 42 | ] 43 | }, 44 | "execution_count": 3, 45 | "metadata": {}, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "a - b" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 4, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "data": { 60 | "text/plain": [ 61 | "15" 62 | ] 63 | }, 64 | "execution_count": 4, 65 | "metadata": {}, 66 | "output_type": "execute_result" 67 | } 68 | ], 69 | "source": [ 70 | "a * b" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 5, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "1.6666666666666667" 82 | ] 83 | }, 84 | "execution_count": 5, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "a / b" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 6, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "data": { 100 | "text/plain": [ 101 | "1" 102 | ] 103 | }, 104 | "execution_count": 6, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "a // b" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 7, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "data": { 120 | "text/plain": [ 121 | "125" 122 | ] 123 | }, 124 | "execution_count": 7, 125 | "metadata": {}, 126 | "output_type": "execute_result" 127 | } 128 | ], 129 | "source": [ 130 | "a ** b" 131 | ] 132 | } 133 | ], 134 | "metadata": { 135 | "kernelspec": { 136 | "display_name": "Python 3", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.11.4" 151 | }, 152 | "orig_nbformat": 4 153 | }, 154 | "nbformat": 4, 155 | "nbformat_minor": 2 156 | } 157 | -------------------------------------------------------------------------------- /control-structure/while-loop.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "i = 1 # initial condition" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 2, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "BCD\n", 22 | "BCD\n", 23 | "BCD\n", 24 | "BCD\n", 25 | "BCD\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "while i <= 5:\n", 31 | " print(\"BCD\")\n", 32 | " i += 1 # i = i + 1" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "i = 1" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 4, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "BCD\n", 54 | "BCD\n", 55 | "BCD\n", 56 | "BCD\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "while i < 5:\n", 62 | " print(\"BCD\")\n", 63 | " i += 1 # i = i + 1" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "# Infinite loop\n", 73 | "\n", 74 | "while True:\n", 75 | " print(\"Hello\")" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 6, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "while False: # always false condition\n", 85 | " print(\"This will not be executed\")" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 7, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "while 0: # always false condition\n", 95 | " print(\"This code will not be executed\")" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 1, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "1 2 3 4 5 \n", 108 | "Loop terminated\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "loop_counter = 1\n", 114 | "while loop_counter <= 5:\n", 115 | " print(loop_counter, end=\" \")\n", 116 | " loop_counter += 1\n", 117 | "else: # when the loop ends, this block will be executed\n", 118 | " print() # new line\n", 119 | " print(\"Loop terminated\")" 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "Python 3", 126 | "language": "python", 127 | "name": "python3" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.11.4" 140 | }, 141 | "orig_nbformat": 4 142 | }, 143 | "nbformat": 4, 144 | "nbformat_minor": 2 145 | } 146 | -------------------------------------------------------------------------------- /basics/variable-value-assignment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "x = 5 # single variable assignment" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 4, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "5\n", 22 | "5\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "a = b = 5 # assigning multiple variables at a time\n", 28 | "print(a)\n", 29 | "print(b)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 5, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "7\n", 42 | "8\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "p, q = 7, 8 # assigning multiple values to multiple variables at a single line\n", 48 | "print(p)\n", 49 | "print(q)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 6, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "Alik\n", 62 | "Avik\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "my_var_1, my_var_2 = \"Alik\", \"Avik\"\n", 68 | "print(my_var_1)\n", 69 | "print(my_var_2)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 7, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "5\n", 82 | "Alik\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "int_var, string_var = 5, \"Alik\"\n", 88 | "print(int_var)\n", 89 | "print(string_var)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 9, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "5\n", 102 | "6\n", 103 | "7\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "#assigning values from a list\n", 109 | "my_list = [5, 6, 7]\n", 110 | "var_1, var_2, var_3 = my_list # unpacking collection\n", 111 | "print(var_1)\n", 112 | "print(var_2)\n", 113 | "print(var_3)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 10, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "1 Alik 5.674\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "new_list = [1, \"Alik\", 5.674] # list supports multiple datatypes\n", 131 | "v_1, v_2, v_3 = new_list\n", 132 | "print(v_1, v_2, v_3)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [] 141 | } 142 | ], 143 | "metadata": { 144 | "kernelspec": { 145 | "display_name": "Python 3", 146 | "language": "python", 147 | "name": "python3" 148 | }, 149 | "language_info": { 150 | "codemirror_mode": { 151 | "name": "ipython", 152 | "version": 3 153 | }, 154 | "file_extension": ".py", 155 | "mimetype": "text/x-python", 156 | "name": "python", 157 | "nbconvert_exporter": "python", 158 | "pygments_lexer": "ipython3", 159 | "version": "3.11.4" 160 | }, 161 | "orig_nbformat": 4 162 | }, 163 | "nbformat": 4, 164 | "nbformat_minor": 2 165 | } 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 |
5 | |
23 |
24 | 26 | Avik Agarwala 27 | 28 | |
29 |
30 |
31 | 33 | Alik Agarwala 34 | 35 | |
|
44 |
45 | 47 | Avik Agarwala 48 | 49 | |
50 |
51 |
52 | 54 | Alik Agarwala 55 | 56 | |
57 |
58 |
59 | 61 | Somnath Sengupta 62 | 63 | |
64 |
65 |
66 | 68 | Sohom Ghosh 69 | 70 | |
71 |
72 |
73 | 75 | Priyam Dutta 76 | 77 | |
78 |
79 |
80 | 82 | ARGHADEEP SARKAR 83 | 84 | |
|
87 |
88 | 90 | ARUNDHUTI SARKAR 91 | 92 | |
93 |
94 |
95 | 97 | Sudipta Mazumdar 98 | 99 | |