├── 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 |
4 | banner image 5 |
6 | 7 | --- 8 | 9 | # Python codes for 💻Binary Coders community (🔒private community) 10 | 11 | We encourage contributions to this repository. If you come across any issues or have ideas for improvements, please don't hesitate to open a pull request. Your input is highly appreciated! 12 | 13 | ### Contribution rules 14 | - Please ensure that your code follows proper alignments and conventions for enhanced readability. 15 | 16 | --- 17 | 18 | ### Authors 19 | 20 | 21 | 22 | 29 | 36 |
23 | 24 | AvikAgarwala 25 |
26 | Avik Agarwala 27 |
28 |
30 | 31 | Alik-Agarwala 32 |
33 | Alik Agarwala 34 |
35 |
37 | 38 | ### Contributors 39 | 40 | 41 | 42 | 43 | 50 | 57 | 64 | 71 | 78 | 85 | 86 | 93 | 100 |
44 | 45 | AvikAgarwala 46 |
47 | Avik Agarwala 48 |
49 |
51 | 52 | Alik-Agarwala 53 |
54 | Alik Agarwala 55 |
56 |
58 | 59 | SomnathSengupta 60 |
61 | Somnath Sengupta 62 |
63 |
65 | 66 | SohomGhosh10 67 |
68 | Sohom Ghosh 69 |
70 |
72 | 73 | Priyam123dutta 74 |
75 | Priyam Dutta 76 |
77 |
79 | 80 | Arghadeeps07 81 |
82 | ARGHADEEP SARKAR 83 |
84 |
87 | 88 | Arundhuti2004 89 |
90 | ARUNDHUTI SARKAR 91 |
92 |
94 | 95 | sudiptamazumdar 96 |
97 | Sudipta Mazumdar 98 |
99 |
101 | 102 | 103 | --- 104 | -------------------------------------------------------------------------------- /basics/variable-naming.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# valid\n", 10 | "myvar = \"Alik\"" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "# valid\n", 20 | "my_var = \"Alik\"" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 3, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "# valid\n", 30 | "myVar = \"Alik\"" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 4, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "# valid\n", 40 | "myvar123 = \"Alik\"" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 5, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "ename": "SyntaxError", 50 | "evalue": "invalid decimal literal (4240209554.py, line 2)", 51 | "output_type": "error", 52 | "traceback": [ 53 | "\u001b[1;36m Cell \u001b[1;32mIn[5], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m 123myvar = \"Alik\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid decimal literal\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "# invalid\n", 59 | "123myvar = \"Alik\"" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 6, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "# valid\n", 69 | "my_var_123 = \"Alik\"" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 7, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "ename": "SyntaxError", 79 | "evalue": "invalid syntax (3046707259.py, line 1)", 80 | "output_type": "error", 81 | "traceback": [ 82 | "\u001b[1;36m Cell \u001b[1;32mIn[7], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m my var = \"Alik\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "# invalid\n", 88 | "my var = \"Alik\"" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 7, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "ename": "SyntaxError", 98 | "evalue": "cannot assign to expression here. Maybe you meant '==' instead of '='? (1995534288.py, line 2)", 99 | "output_type": "error", 100 | "traceback": [ 101 | "\u001b[1;36m Cell \u001b[1;32mIn[7], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m my-var = \"Alik\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m cannot assign to expression here. Maybe you meant '==' instead of '='?\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "# invalid\n", 107 | "my-var = \"Alik\"" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 8, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "# valid\n", 117 | "My_var = \"Alik\"" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 10, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "# valid\n", 127 | "_my_var = \"Alik\"" 128 | ] 129 | } 130 | ], 131 | "metadata": { 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.11.4" 148 | }, 149 | "orig_nbformat": 4 150 | }, 151 | "nbformat": 4, 152 | "nbformat_minor": 2 153 | } 154 | -------------------------------------------------------------------------------- /control-structure/for-loop.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 | "0 1 2 3 4 " 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "for i in range(5): # 0 to 4\n", 18 | " print(i, end=\" \")" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 4, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "1 2 3 4 5 6 " 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "for i in range(1, 7): # 1 to 6\n", 36 | " print(i, end=\" \")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 7, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "2 4 6 8 10 " 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "for i in range(2, 11, 2): # 2 to 10, increment by 2\n", 54 | " print(i, end=\" \")" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 12, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "10 9 8 7 6 5 4 3 2 1 " 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "for i in range(10, 0, -1): # 1 to 10, decrement by 1\n", 72 | " print(i, end=\" \")" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 20, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "name": "stdout", 82 | "output_type": "stream", 83 | "text": [ 84 | "25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 " 85 | ] 86 | } 87 | ], 88 | "source": [ 89 | "for i in range(5, 50):\n", 90 | " print(i * 5, end=\" \")" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 22, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "0 1 2 3 4 Terminated\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "for i in range(5):\n", 108 | " print(i, end=\" \")\n", 109 | "else: # when loop terminates\n", 110 | " print(\"Terminated\")" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 23, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "1 2 3 " 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "for i in range(1, 6):\n", 128 | " if i == 4:\n", 129 | " break\n", 130 | " print(i, end=\" \")" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 29, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "1 2 3 5 6 " 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "for i in range(1, 7):\n", 148 | " if i == 4:\n", 149 | " continue\n", 150 | " print(i, end=\" \")" 151 | ] 152 | } 153 | ], 154 | "metadata": { 155 | "kernelspec": { 156 | "display_name": "Python 3", 157 | "language": "python", 158 | "name": "python3" 159 | }, 160 | "language_info": { 161 | "codemirror_mode": { 162 | "name": "ipython", 163 | "version": 3 164 | }, 165 | "file_extension": ".py", 166 | "mimetype": "text/x-python", 167 | "name": "python", 168 | "nbconvert_exporter": "python", 169 | "pygments_lexer": "ipython3", 170 | "version": "3.11.4" 171 | }, 172 | "orig_nbformat": 4 173 | }, 174 | "nbformat": 4, 175 | "nbformat_minor": 2 176 | } 177 | -------------------------------------------------------------------------------- /data-structure/tuple.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "t = ('Avik', 18, True, 5.6) # tuple" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 3, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "18\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "print(t[1])" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 4, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "ename": "TypeError", 36 | "evalue": "'tuple' object does not support item assignment", 37 | "output_type": "error", 38 | "traceback": [ 39 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 40 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 41 | "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m t[\u001b[39m1\u001b[39;49m] \u001b[39m=\u001b[39m \u001b[39m12\u001b[39m\n", 42 | "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "t[1] = 12 # cannot perform as tuple is immutable" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 6, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "data": { 57 | "text/plain": [ 58 | "3" 59 | ] 60 | }, 61 | "execution_count": 6, 62 | "metadata": {}, 63 | "output_type": "execute_result" 64 | } 65 | ], 66 | "source": [ 67 | "t = (2, 5, 7, 5, 6, 5, 3)\n", 68 | "t.count(5)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 8, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "data": { 78 | "text/plain": [ 79 | "2" 80 | ] 81 | }, 82 | "execution_count": 8, 83 | "metadata": {}, 84 | "output_type": "execute_result" 85 | } 86 | ], 87 | "source": [ 88 | "t.index(7) # find the index of the specified value" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 10, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "text/plain": [ 99 | "tuple" 100 | ] 101 | }, 102 | "execution_count": 10, 103 | "metadata": {}, 104 | "output_type": "execute_result" 105 | } 106 | ], 107 | "source": [ 108 | "type(t)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 19, 114 | "metadata": {}, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "(87, 56, 9, 5, 3)\n" 121 | ] 122 | }, 123 | { 124 | "data": { 125 | "text/plain": [ 126 | "tuple" 127 | ] 128 | }, 129 | "execution_count": 19, 130 | "metadata": {}, 131 | "output_type": "execute_result" 132 | } 133 | ], 134 | "source": [ 135 | "# Q) Sort a provided tuple\n", 136 | "\n", 137 | "t = (5, 9, 3, 87, 56)\n", 138 | "t = list(t)\n", 139 | "'''\n", 140 | "# ascending order sort\n", 141 | "t.sort()\n", 142 | "'''\n", 143 | "t.sort(reverse=True) #desceding order sort\n", 144 | "t = tuple(t)\n", 145 | "print(t)\n", 146 | "type(t)" 147 | ] 148 | } 149 | ], 150 | "metadata": { 151 | "kernelspec": { 152 | "display_name": "Python 3", 153 | "language": "python", 154 | "name": "python3" 155 | }, 156 | "language_info": { 157 | "codemirror_mode": { 158 | "name": "ipython", 159 | "version": 3 160 | }, 161 | "file_extension": ".py", 162 | "mimetype": "text/x-python", 163 | "name": "python", 164 | "nbconvert_exporter": "python", 165 | "pygments_lexer": "ipython3", 166 | "version": "3.11.4" 167 | }, 168 | "orig_nbformat": 4 169 | }, 170 | "nbformat": 4, 171 | "nbformat_minor": 2 172 | } 173 | -------------------------------------------------------------------------------- /oop/class-object.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 | "Pritha has 2 eyes\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "class Human: # defining class\n", 18 | " nose = 1\n", 19 | " eyes = 2\n", 20 | "\n", 21 | "pritha = Human() # creating an object of Human class\n", 22 | "apabrita = Human() # creating another object\n", 23 | "\n", 24 | "# Pritha has 2 eyes\n", 25 | "print(f\"Pritha has {pritha.eyes} eyes\")" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 8, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "h1's name is Nabanita\n", 38 | "h1's age is 18\n", 39 | "h2's name is Shreyasi\n", 40 | "h2's age is None\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "class Human:\n", 46 | " name = None\n", 47 | " age = None\n", 48 | " eyes = 2\n", 49 | "\n", 50 | "# main\n", 51 | "h1 = Human() #real life object\n", 52 | "h1.name = \"Nabanita\"\n", 53 | "h1.age = 18\n", 54 | "\n", 55 | "h2 = Human()\n", 56 | "h2.name = \"Shreyasi\"\n", 57 | "\n", 58 | "\n", 59 | "print(f\"h1's name is {h1.name}\")\n", 60 | "print(f\"h1's age is {h1.age}\")\n", 61 | "\n", 62 | "print(f\"h2's name is {h2.name}\")\n", 63 | "print(f\"h2's age is {h2.age}\")" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 23, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "I love to code !\n", 76 | "I love to code !\n", 77 | "I love to code !\n" 78 | ] 79 | }, 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "'\\n# alternative way\\n\\nCoder.hobby(a)\\nCoder.hobby(b)\\nCoder.hobby(c)\\n'" 84 | ] 85 | }, 86 | "execution_count": 23, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "class Coder:\n", 93 | " # attribute\n", 94 | " name = None\n", 95 | "\n", 96 | " # method\n", 97 | " def hobby(self):\n", 98 | " print(\"I love to code !\")\n", 99 | "\n", 100 | "a = Coder() # creating object\n", 101 | "b = Coder() # creating object\n", 102 | "c = Coder() # creating object\n", 103 | "\n", 104 | "a.hobby()\n", 105 | "b.hobby()\n", 106 | "c.hobby()\n", 107 | "\n", 108 | "'''\n", 109 | "# alternative way\n", 110 | "\n", 111 | "Coder.hobby(a)\n", 112 | "Coder.hobby(b)\n", 113 | "Coder.hobby(c)\n", 114 | "'''\n" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 29, 120 | "metadata": {}, 121 | "outputs": [ 122 | { 123 | "name": "stdout", 124 | "output_type": "stream", 125 | "text": [ 126 | "Avik loves to code !\n", 127 | "Blob loves to code !\n", 128 | "Charizard loves to code !\n" 129 | ] 130 | } 131 | ], 132 | "source": [ 133 | "class Coder:\n", 134 | " # attribute\n", 135 | " name = None\n", 136 | "\n", 137 | " # method\n", 138 | " def hobby(self, name):\n", 139 | " print(f\"{name} loves to code !\")\n", 140 | "\n", 141 | "a = Coder() # creating object\n", 142 | "b = Coder() # creating object\n", 143 | "c = Coder() # creating object\n", 144 | "\n", 145 | "a.hobby(\"Avik\")\n", 146 | "# b.hobby(\"Blob\")\n", 147 | "Coder.hobby(b, \"Blob\")\n", 148 | "c.hobby(\"Charizard\")\n" 149 | ] 150 | } 151 | ], 152 | "metadata": { 153 | "kernelspec": { 154 | "display_name": "Python 3", 155 | "language": "python", 156 | "name": "python3" 157 | }, 158 | "language_info": { 159 | "codemirror_mode": { 160 | "name": "ipython", 161 | "version": 3 162 | }, 163 | "file_extension": ".py", 164 | "mimetype": "text/x-python", 165 | "name": "python", 166 | "nbconvert_exporter": "python", 167 | "pygments_lexer": "ipython3", 168 | "version": "3.11.4" 169 | }, 170 | "orig_nbformat": 4 171 | }, 172 | "nbformat": 4, 173 | "nbformat_minor": 2 174 | } 175 | -------------------------------------------------------------------------------- /function/user-defined-function.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 | "Starting of program...\n", 13 | "Hello Avik\n", 14 | "Calling again...\n", 15 | "Hello Sumit\n" 16 | ] 17 | } 18 | ], 19 | "source": [ 20 | "# function definition\n", 21 | "def greet():\n", 22 | " name = input(\"Enter your name : \")\n", 23 | " print(\"Hello\", name)\n", 24 | "\n", 25 | "# start of main\n", 26 | "print(\"Starting of program...\")\n", 27 | "greet()\n", 28 | "print(\"Calling again...\")\n", 29 | "greet()" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 8, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "Hello Avik\n" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "def greet(x):\n", 47 | " print(\"Hello\", x)\n", 48 | "\n", 49 | "# main\n", 50 | "name = input(\"Enter your name: \")\n", 51 | "greet(name)\n" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 9, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "Hello Avik\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "def greet(name):\n", 69 | " print(\"Hello\", name)\n", 70 | "\n", 71 | "# main\n", 72 | "name = input(\"Enter your name: \")\n", 73 | "greet(name)\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 10, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "Sum is 11\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "def sum(x, y):\n", 91 | " ans = x + y\n", 92 | " return ans\n", 93 | "\n", 94 | "\n", 95 | "x = int(input(\"Enter first number: \"))\n", 96 | "y = int(input(\"Enter second number: \"))\n", 97 | "result = sum(x, y)\n", 98 | "print(f\"Sum is {result}\")" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 13, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "Sum is 11\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "def sum(x, y):\n", 116 | " # ans = x + y\n", 117 | " return x + y\n", 118 | "\n", 119 | "\n", 120 | "x = int(input(\"Enter first number: \"))\n", 121 | "y = int(input(\"Enter second number: \"))\n", 122 | "# result = sum(x, y)\n", 123 | "# print(f\"Sum is {result}\")\n", 124 | "print(f\"Sum is {sum(x, y)}\")" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 17, 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "ename": "TypeError", 134 | "evalue": "sum() missing 1 required positional argument: 'y'", 135 | "output_type": "error", 136 | "traceback": [ 137 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 138 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 139 | "Cell \u001b[1;32mIn[17], line 5\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39msum\u001b[39m(x, y):\n\u001b[0;32m 2\u001b[0m \u001b[39mreturn\u001b[39;00m x \u001b[39m+\u001b[39m y\n\u001b[1;32m----> 5\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mSum is \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39msum\u001b[39;49m(\u001b[39m5\u001b[39;49m)\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n", 140 | "\u001b[1;31mTypeError\u001b[0m: sum() missing 1 required positional argument: 'y'" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "def sum(x, y):\n", 146 | " return x + y\n", 147 | "\n", 148 | "\n", 149 | "print(f\"Sum is {sum(5)}\")" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 19, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "name": "stdout", 159 | "output_type": "stream", 160 | "text": [ 161 | "Sum is 10\n", 162 | "Sum is 11\n" 163 | ] 164 | } 165 | ], 166 | "source": [ 167 | "def sum(x, y = 6): # 6 will be considered if y is not passed\n", 168 | " return x + y\n", 169 | "\n", 170 | "\n", 171 | "print(f\"Sum is {sum(5, 5)}\")\n", 172 | "print(f\"Sum is {sum(5)}\")" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 33, 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "Hello\n" 185 | ] 186 | } 187 | ], 188 | "source": [ 189 | "def greet():\n", 190 | " print(\"Hello\")\n", 191 | "\n", 192 | "def i_dont_know(): # to be implemented later\n", 193 | " pass # to avoid error\n", 194 | "\n", 195 | "# main\n", 196 | "greet()\n", 197 | "i_dont_know()" 198 | ] 199 | } 200 | ], 201 | "metadata": { 202 | "kernelspec": { 203 | "display_name": "Python 3", 204 | "language": "python", 205 | "name": "python3" 206 | }, 207 | "language_info": { 208 | "codemirror_mode": { 209 | "name": "ipython", 210 | "version": 3 211 | }, 212 | "file_extension": ".py", 213 | "mimetype": "text/x-python", 214 | "name": "python", 215 | "nbconvert_exporter": "python", 216 | "pygments_lexer": "ipython3", 217 | "version": "3.11.4" 218 | }, 219 | "orig_nbformat": 4 220 | }, 221 | "nbformat": 4, 222 | "nbformat_minor": 2 223 | } 224 | -------------------------------------------------------------------------------- /data-structure/list.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "my_list = [\"Alik\", \"Avik\", \"Souvik\"] # list creation" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 3, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "['Alik', 'Avik', 'Souvik']\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "print(my_list)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 4, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "[]\n" 39 | ] 40 | } 41 | ], 42 | "source": [ 43 | "# blank list\n", 44 | "blank_list = []\n", 45 | "print(blank_list)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 5, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "Alik\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "#access by index\n", 63 | "print(my_list[0])" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 6, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "[1, 2, 2, 3, 4, 4]\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "new_list = [1, 2, 2, 3, 4, 4]\n", 81 | "print(new_list)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 8, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "['Alik da', 'Avik']\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "list_1 = [\"Alik\", \"Avik\"]\n", 99 | "list_1[0] = \"Alik da\"\n", 100 | "print(list_1)" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 9, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "[4, 8, 2]\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "long_list = [5, 4, 8, 2, 1, 3, 4, 5, 9]\n", 118 | "print(long_list[1:4]) # list slicing" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 10, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "[4, 56, 65, 101, 10, 450]\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "another_list = [4, 78, 96, 101, 10, 450]\n", 136 | "another_list[1:3] = [56, 65] # changing a range\n", 137 | "print(another_list)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 13, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "[5, 75, 85, 95, 78, 8, 2, 1, 3, 4, 5, 9]\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "long_list = [5, 4, 8, 2, 1, 3, 4, 5, 9]\n", 155 | "long_list[1:2] = [75, 85, 95, 78]\n", 156 | "print(long_list)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 14, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "[5, 75, 85, 95, 78, 2, 1, 3, 4, 5, 9]\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "long_list = [5, 4, 8, 2, 1, 3, 4, 5, 9]\n", 174 | "long_list[1:3] = [75, 85, 95, 78]\n", 175 | "print(long_list)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 15, 181 | "metadata": {}, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "['Alik', 'Somnath']\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "short_list = [\"Alik\", \"Avik\", \"Rajdeep\"]\n", 193 | "short_list[1:3] = [\"Somnath\"]\n", 194 | "print(short_list)" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 16, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "[16, 7]\n" 207 | ] 208 | } 209 | ], 210 | "source": [ 211 | "new_list = [5, 6, 7, 8, 16, 7, 9]\n", 212 | "print(new_list[-3:-1])" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 19, 218 | "metadata": {}, 219 | "outputs": [ 220 | { 221 | "name": "stdout", 222 | "output_type": "stream", 223 | "text": [ 224 | "1 3 Alik 4.56 Avik True False " 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "new_list = [1, 3, \"Alik\", 4.56, \"Avik\", True, False]\n", 230 | "for i in new_list: # traversing a list\n", 231 | " print(i, end=\" \")" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": 20, 237 | "metadata": {}, 238 | "outputs": [ 239 | { 240 | "name": "stdout", 241 | "output_type": "stream", 242 | "text": [ 243 | "present\n" 244 | ] 245 | } 246 | ], 247 | "source": [ 248 | "new_list = [1, 3, \"Alik\", 4.56, \"Avik\", True, False]\n", 249 | "if \"Alik\" in new_list:\n", 250 | " print(\"present\")" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 21, 256 | "metadata": {}, 257 | "outputs": [ 258 | { 259 | "name": "stdout", 260 | "output_type": "stream", 261 | "text": [ 262 | "[5, 6, 1, 8, 9, 15]\n" 263 | ] 264 | } 265 | ], 266 | "source": [ 267 | "l1 = [5, 6, 1, 8, 9]\n", 268 | "l1.append(15) # insert at last\n", 269 | "print(l1)" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 23, 275 | "metadata": {}, 276 | "outputs": [ 277 | { 278 | "name": "stdout", 279 | "output_type": "stream", 280 | "text": [ 281 | "[1, 2, 3, 5, 6, 7]\n" 282 | ] 283 | } 284 | ], 285 | "source": [ 286 | "l1 = [1, 2, 3, 6, 7]\n", 287 | "l1.insert(3, 5)\n", 288 | "print(l1)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 24, 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "name": "stdout", 298 | "output_type": "stream", 299 | "text": [ 300 | "[1, 2, 3, 4, 5, 6]\n" 301 | ] 302 | } 303 | ], 304 | "source": [ 305 | "l1 = [1, 2, 3]\n", 306 | "l2 = [4, 5, 6]\n", 307 | "l1.extend(l2)\n", 308 | "print(l1)" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 25, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "name": "stdout", 318 | "output_type": "stream", 319 | "text": [ 320 | "[1, 2, 3, 4, 5]\n" 321 | ] 322 | } 323 | ], 324 | "source": [ 325 | "l1 = [1, 2, 3, 4, 5, 6]\n", 326 | "l1.pop() # remove from last\n", 327 | "print(l1)" 328 | ] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": 27, 333 | "metadata": {}, 334 | "outputs": [ 335 | { 336 | "name": "stdout", 337 | "output_type": "stream", 338 | "text": [ 339 | "[2, 3, 4, 5, 6]\n" 340 | ] 341 | } 342 | ], 343 | "source": [ 344 | "l1 = [1, 2, 3, 4, 5, 6]\n", 345 | "l1.pop(0) # remove element from index 0\n", 346 | "print(l1)" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 30, 352 | "metadata": {}, 353 | "outputs": [ 354 | { 355 | "name": "stdout", 356 | "output_type": "stream", 357 | "text": [ 358 | "[1, 3, 4, 2, 5, 6]\n" 359 | ] 360 | } 361 | ], 362 | "source": [ 363 | "l1 = [1, 2, 3, 4, 2, 5, 6]\n", 364 | "l1.remove(2) # remove first occurrence of 2\n", 365 | "print(l1)" 366 | ] 367 | }, 368 | { 369 | "cell_type": "code", 370 | "execution_count": 31, 371 | "metadata": {}, 372 | "outputs": [ 373 | { 374 | "name": "stdout", 375 | "output_type": "stream", 376 | "text": [ 377 | "[]\n" 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "l1 = [1, 2, 3, 4, 2, 5, 6]\n", 383 | "l1.clear() # remove all the elements\n", 384 | "print(l1)" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 32, 390 | "metadata": {}, 391 | "outputs": [ 392 | { 393 | "name": "stdout", 394 | "output_type": "stream", 395 | "text": [ 396 | "[2, 3, 4, 2, 5, 6]\n" 397 | ] 398 | } 399 | ], 400 | "source": [ 401 | "l1 = [1, 2, 3, 4, 2, 5, 6]\n", 402 | "del l1[0] # remove element from index 0\n", 403 | "print(l1)" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 34, 409 | "metadata": {}, 410 | "outputs": [ 411 | { 412 | "ename": "NameError", 413 | "evalue": "name 'l1' is not defined", 414 | "output_type": "error", 415 | "traceback": [ 416 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 417 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 418 | "Cell \u001b[1;32mIn[34], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m l1 \u001b[39m=\u001b[39m [\u001b[39m1\u001b[39m, \u001b[39m2\u001b[39m, \u001b[39m3\u001b[39m, \u001b[39m4\u001b[39m, \u001b[39m2\u001b[39m, \u001b[39m5\u001b[39m, \u001b[39m6\u001b[39m]\n\u001b[0;32m 2\u001b[0m \u001b[39mdel\u001b[39;00m l1 \u001b[39m# delete l1 from memory\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[39mprint\u001b[39m(l1)\n", 419 | "\u001b[1;31mNameError\u001b[0m: name 'l1' is not defined" 420 | ] 421 | } 422 | ], 423 | "source": [ 424 | "l1 = [1, 2, 3, 4, 2, 5, 6]\n", 425 | "del l1 # delete l1 from memory\n", 426 | "print(l1)" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 35, 432 | "metadata": {}, 433 | "outputs": [ 434 | { 435 | "name": "stdout", 436 | "output_type": "stream", 437 | "text": [ 438 | "[3, 4, 6, 7, 8, 9]\n" 439 | ] 440 | } 441 | ], 442 | "source": [ 443 | "# sort a list\n", 444 | "number_list = [4, 6, 8, 3, 9, 7]\n", 445 | "number_list.sort()\n", 446 | "print(number_list)" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": 36, 452 | "metadata": {}, 453 | "outputs": [ 454 | { 455 | "name": "stdout", 456 | "output_type": "stream", 457 | "text": [ 458 | "['Alik', 'Apabrita', 'Avik', 'Somnath']\n" 459 | ] 460 | } 461 | ], 462 | "source": [ 463 | "string_list = [\"Alik\", \"Somnath\", \"Apabrita\", \"Avik\"]\n", 464 | "string_list.sort()\n", 465 | "print(string_list)" 466 | ] 467 | }, 468 | { 469 | "cell_type": "code", 470 | "execution_count": 37, 471 | "metadata": {}, 472 | "outputs": [ 473 | { 474 | "ename": "TypeError", 475 | "evalue": "'<' not supported between instances of 'str' and 'int'", 476 | "output_type": "error", 477 | "traceback": [ 478 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 479 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 480 | "Cell \u001b[1;32mIn[37], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m l1 \u001b[39m=\u001b[39m [\u001b[39m23\u001b[39m, \u001b[39m45\u001b[39m, \u001b[39m12\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mAlik\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mCar\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m78\u001b[39m, \u001b[39m4.25\u001b[39m, \u001b[39mTrue\u001b[39;00m, \u001b[39mFalse\u001b[39;00m]\n\u001b[1;32m----> 2\u001b[0m l1\u001b[39m.\u001b[39;49msort()\n", 481 | "\u001b[1;31mTypeError\u001b[0m: '<' not supported between instances of 'str' and 'int'" 482 | ] 483 | } 484 | ], 485 | "source": [ 486 | "l1 = [23, 45, 12, \"Alik\", \"Car\", 78, 4.25, True, False]\n", 487 | "l1.sort()" 488 | ] 489 | }, 490 | { 491 | "cell_type": "code", 492 | "execution_count": 1, 493 | "metadata": {}, 494 | "outputs": [ 495 | { 496 | "data": { 497 | "text/plain": [ 498 | "4" 499 | ] 500 | }, 501 | "execution_count": 1, 502 | "metadata": {}, 503 | "output_type": "execute_result" 504 | } 505 | ], 506 | "source": [ 507 | "l = [1,2,4,4,4,4]\n", 508 | "l.count(4)" 509 | ] 510 | } 511 | ], 512 | "metadata": { 513 | "kernelspec": { 514 | "display_name": "Python 3", 515 | "language": "python", 516 | "name": "python3" 517 | }, 518 | "language_info": { 519 | "codemirror_mode": { 520 | "name": "ipython", 521 | "version": 3 522 | }, 523 | "file_extension": ".py", 524 | "mimetype": "text/x-python", 525 | "name": "python", 526 | "nbconvert_exporter": "python", 527 | "pygments_lexer": "ipython3", 528 | "version": "3.11.4" 529 | }, 530 | "orig_nbformat": 4 531 | }, 532 | "nbformat": 4, 533 | "nbformat_minor": 2 534 | } 535 | --------------------------------------------------------------------------------