├── 1-Python Basics ├── 1.0-basic.ipynb ├── 1.1-Variables.ipynb ├── 1.2-Datatypes.ipynb ├── 1.3-operators.ipynb └── test.py ├── 10-Data Analysis With Python ├── 10.1-numpy.ipynb ├── 10.2-pandas.ipynb ├── 10.3-datamanipulation.ipynb ├── 10.4-readdata.ipynb ├── 10.5-matplotlib.ipynb ├── 10.6-seaborn.ipynb ├── data.csv ├── data.xlsx ├── df_excel ├── sales1_data.csv ├── sales_data.csv ├── sample_data.xlsx └── wine.csv ├── 11-Working With Databases ├── 11.1-sqlite.ipynb ├── example.db └── sales_data.db ├── 12-Logging In Python ├── 12.1-logging.ipynb ├── 12.2-multiplelogger.ipynb ├── app.log ├── app.py ├── app1.log └── logs │ ├── __pycache__ │ └── logger.cpython-312.pyc │ ├── app.log │ ├── logger.py │ └── test.py ├── 13-Flask └── flask │ ├── api.py │ ├── app.py │ ├── getpost.py │ ├── jinja.py │ ├── main.py │ ├── sample.json │ └── templates │ ├── about.html │ ├── form.html │ ├── getresult.html │ ├── index.html │ ├── result.html │ └── result1.html ├── 14-Streamlit ├── app.py ├── classification.py ├── sampledata.csv ├── streamlit.ipynb └── widgets.py ├── 15-Memory Management └── memory_manage.ipynb ├── 16-Multithreading and Multiprocessing ├── advance_multi_processing.py ├── advance_multi_threading.py ├── factorial_multi_processing.py ├── multi_processing.py ├── multi_threading.py └── webscrapping_multi_threading.py ├── 2-Control Flow ├── Conditionalstatements.ipynb └── Loops.ipynb ├── 3-Data Structures ├── 3.1-Lists.ipynb ├── 3.1.1-ListExamples.ipynb ├── 3.2-Tuples.ipynb ├── 3.3-Sets.ipynb └── 3.4-Dictionaries.ipynb ├── 4-Functions ├── 4.1-functions.ipynb ├── 4.2-examplesfunctions.ipynb ├── 4.3-Lambda.ipynb ├── 4.4-Mapsfunction.ipynb ├── 4.5-filterfunction.ipynb └── sample.txt ├── 5-Modules ├── 5.1-import.ipynb ├── 5.2-Standardlibrary.ipynb ├── destination.txt ├── example.csv ├── package │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-312.pyc │ │ └── maths.cpython-312.pyc │ ├── maths.py │ └── subpackages │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── __init__.cpython-312.pyc │ │ └── mult.cpython-312.pyc │ │ └── mult.py ├── source.txt └── test.py ├── 6-File Handling ├── 6.1-fileoperation.ipynb ├── 6.2-filepath.ipynb ├── destination.txt ├── example.bin └── example.txt ├── 7-Exception Handling ├── 7.1-exception.ipynb └── example1.txt ├── 8-Class And Objects ├── 8.1-oops.ipynb ├── 8.2-inheritance.ipynb ├── 8.3-Polymorphism.ipynb ├── 8.4-Encapsulation.ipynb ├── 8.5-Abstraction.ipynb ├── 8.6-magicmethods.ipynb └── 8.7-OperatorOverloading.ipynb ├── 9-Advance Python Concepts ├── 9.1-Iterators.ipynb ├── 9.2-Generators.ipynb ├── 9.3-Decorators.ipynb └── large_file.txt ├── LICENSE ├── README.md └── requirements.txt /1-Python Basics/1.0-basic.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Syntax and Semantics in Python\n", 8 | "Video Outline:\n", 9 | "- Single line Comments and multiline comments \n", 10 | "- Definition of Syntax and Semantics\n", 11 | "- Basic Syntax Rules in Python\n", 12 | "- Understanding Semantics in Python\n", 13 | "- Common Syntax Errors and How to Avoid Them\n", 14 | "- Practical Code Examples" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "Syntax refers to the set of rules that defines the combinations of symbols that are considered to be correctly structured programs in a language. In simpler terms, syntax is about the correct arrangement of words and symbols in a code.\n", 22 | "\n", 23 | "Semantics refers to the meaning or the interpretation of the symbols, characters, and commands in a language. It is about what the code is supposed to do when it runs." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 1, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "Krish\n", 36 | "Naik\n" 37 | ] 38 | } 39 | ], 40 | "source": [ 41 | "## Basic Syntax Rules In Python\n", 42 | "## Case sensitivity- Python is case sensitive\n", 43 | "\n", 44 | "name=\"Krish\"\n", 45 | "Name=\"Naik\"\n", 46 | "\n", 47 | "print(name)\n", 48 | "print(Name)\n" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "### Indentation\n", 56 | "Indentation in Python is used to define the structure and hierarchy of the code. Unlike many other programming languages that use braces {} to delimit blocks of code, Python uses indentation to determine the grouping of statements. This means that all the statements within a block must be indented at the same level." 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 2, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "32\n", 69 | "32\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "## Indentation\n", 75 | "## Python uses indentation to define blocks of code. Consistent use of spaces (commonly 4) or a tab is required.\n", 76 | "\n", 77 | "age=32\n", 78 | "if age>30:\n", 79 | " \n", 80 | " print(age)\n", 81 | " \n", 82 | "print(age)\n" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 3, 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "Hello World\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "## This is a single line comment\n", 100 | "print(\"Hello World\")" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 5, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "43\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "## Line Continuation\n", 118 | "##Use a backslash (\\) to continue a statement to the next line\n", 119 | "\n", 120 | "total=1+2+3+4+5+6+7+\\\n", 121 | "4+5+6\n", 122 | "\n", 123 | "print(total)\n" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 6, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "15\n" 136 | ] 137 | } 138 | ], 139 | "source": [ 140 | "## Multiple Statements on a single line\n", 141 | "x=5;y=10;z=x+y\n", 142 | "print(z)" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 7, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "##Understand Semnatics In Python\n", 152 | "# variable assignment\n", 153 | "age=32 ##age is an integer\n", 154 | "name=\"Krish\" ##name is a string" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 10, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "data": { 164 | "text/plain": [ 165 | "int" 166 | ] 167 | }, 168 | "execution_count": 10, 169 | "metadata": {}, 170 | "output_type": "execute_result" 171 | } 172 | ], 173 | "source": [ 174 | "\n", 175 | "\n", 176 | "type(age)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 9, 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "data": { 186 | "text/plain": [ 187 | "str" 188 | ] 189 | }, 190 | "execution_count": 9, 191 | "metadata": {}, 192 | "output_type": "execute_result" 193 | } 194 | ], 195 | "source": [ 196 | "type(name)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 12, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "\n", 209 | "\n" 210 | ] 211 | } 212 | ], 213 | "source": [ 214 | "## Type Inference\n", 215 | "variable=10\n", 216 | "print(type(variable))\n", 217 | "variable=\"Krish\"\n", 218 | "print(type(variable))" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 14, 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "name": "stdout", 228 | "output_type": "stream", 229 | "text": [ 230 | "32\n" 231 | ] 232 | } 233 | ], 234 | "source": [ 235 | "age=32\n", 236 | "if age>30:\n", 237 | " print(age)" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 15, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "ename": "NameError", 247 | "evalue": "name 'b' is not defined", 248 | "output_type": "error", 249 | "traceback": [ 250 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 251 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 252 | "Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m a\u001b[38;5;241m=\u001b[39m\u001b[43mb\u001b[49m\n", 253 | "\u001b[1;31mNameError\u001b[0m: name 'b' is not defined" 254 | ] 255 | } 256 | ], 257 | "source": [ 258 | "## Name Error\n", 259 | "a=b" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 17, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "name": "stdout", 269 | "output_type": "stream", 270 | "text": [ 271 | "Correct Indentation\n", 272 | "This will print\n", 273 | "Outside the if block\n" 274 | ] 275 | } 276 | ], 277 | "source": [ 278 | "## Code exmaples of indentation\n", 279 | "if True:\n", 280 | " print(\"Correct Indentation\")\n", 281 | " if False:\n", 282 | " print(\"This ont print\")\n", 283 | " print(\"This will print\")\n", 284 | "print(\"Outside the if block\")" 285 | ] 286 | }, 287 | { 288 | "cell_type": "markdown", 289 | "metadata": {}, 290 | "source": [ 291 | "### Conclusion:\n", 292 | "Understanding the syntax and semantics of Python is crucial for writing correct and meaningful programs. Syntax ensures the code is properly structured, while semantics ensures the code behaves as expected. Mastering these concepts will help in writing efficient and error-free Python code." 293 | ] 294 | }, 295 | { 296 | "cell_type": "markdown", 297 | "metadata": {}, 298 | "source": [] 299 | } 300 | ], 301 | "metadata": { 302 | "kernelspec": { 303 | "display_name": "Python 3", 304 | "language": "python", 305 | "name": "python3" 306 | }, 307 | "language_info": { 308 | "codemirror_mode": { 309 | "name": "ipython", 310 | "version": 3 311 | }, 312 | "file_extension": ".py", 313 | "mimetype": "text/x-python", 314 | "name": "python", 315 | "nbconvert_exporter": "python", 316 | "pygments_lexer": "ipython3", 317 | "version": "3.12.0" 318 | } 319 | }, 320 | "nbformat": 4, 321 | "nbformat_minor": 2 322 | } 323 | -------------------------------------------------------------------------------- /1-Python Basics/1.2-Datatypes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## DataTypes\n", 8 | "#### 1. Definition:\n", 9 | "\n", 10 | "- Data types are a classification of data which tell the compiler or interpreter how the programmer intends to use the data.\n", 11 | "- They determine the type of operations that can be performed on the data, the values that the data can take, and the amount of memory needed to store the data.\n", 12 | "\n", 13 | "#### 2. Importance of Data Types in Programming\n", 14 | "Explanation:\n", 15 | "\n", 16 | "- Data types ensure that data is stored in an efficient way.\n", 17 | "- They help in performing correct operations on data.\n", 18 | "- Proper use of data types can prevent errors and bugs in the program." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "Video Outline:\n", 26 | "1. Introduction to Data Types\n", 27 | "2. Importance of Data Types in Programming\n", 28 | "3. Basic Data Types\n", 29 | " - Integers\n", 30 | " - Floating-point numbers\n", 31 | " - Strings\n", 32 | " - Booleans\n", 33 | "4. Advanced Data Types\n", 34 | " - Lists\n", 35 | " - Tuples\n", 36 | " - Sets\n", 37 | " - Dictionaries\n", 38 | "5. Type Conversion\n", 39 | "6. Practical Examples" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 1, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "data": { 49 | "text/plain": [ 50 | "int" 51 | ] 52 | }, 53 | "execution_count": 1, 54 | "metadata": {}, 55 | "output_type": "execute_result" 56 | } 57 | ], 58 | "source": [ 59 | "## Integer Example\n", 60 | "age=35\n", 61 | "type(age)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 2, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "5.11\n", 74 | "\n" 75 | ] 76 | } 77 | ], 78 | "source": [ 79 | "##floating point datatype\n", 80 | "height=5.11\n", 81 | "print(height)\n", 82 | "print(type(height))\n" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 3, 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "Krish\n", 95 | "\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "## string datatype example\n", 101 | "name=\"Krish\"\n", 102 | "print(name)\n", 103 | "print(type(name))" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 7, 109 | "metadata": {}, 110 | "outputs": [ 111 | { 112 | "data": { 113 | "text/plain": [ 114 | "bool" 115 | ] 116 | }, 117 | "execution_count": 7, 118 | "metadata": {}, 119 | "output_type": "execute_result" 120 | } 121 | ], 122 | "source": [ 123 | "## boolean datatype\n", 124 | "is_true=True\n", 125 | "type(is_true)" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 11, 131 | "metadata": {}, 132 | "outputs": [ 133 | { 134 | "data": { 135 | "text/plain": [ 136 | "bool" 137 | ] 138 | }, 139 | "execution_count": 11, 140 | "metadata": {}, 141 | "output_type": "execute_result" 142 | } 143 | ], 144 | "source": [ 145 | "a=10\n", 146 | "b=10\n", 147 | "\n", 148 | "type(a==b)\n" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 12, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "ename": "TypeError", 158 | "evalue": "can only concatenate str (not \"int\") to str", 159 | "output_type": "error", 160 | "traceback": [ 161 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 162 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 163 | "Cell \u001b[1;32mIn[12], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m## common errors\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m result\u001b[38;5;241m=\u001b[39m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mHello\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\n", 164 | "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 165 | ] 166 | } 167 | ], 168 | "source": [ 169 | "## common errors\n", 170 | "\n", 171 | "result=\"Hello\" + 5\n", 172 | " " 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 14, 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "Hello5\n" 185 | ] 186 | } 187 | ], 188 | "source": [ 189 | "result=\"Hello\" + str(5)\n", 190 | "print(result)" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [] 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.12.0" 218 | } 219 | }, 220 | "nbformat": 4, 221 | "nbformat_minor": 2 222 | } 223 | -------------------------------------------------------------------------------- /1-Python Basics/test.py: -------------------------------------------------------------------------------- 1 | ## this is single line comment 2 | ''' 3 | this is a exmaple of multiline comments 4 | ''' 5 | ''' 6 | Welcome to the 7 | python course 8 | 9 | 10 | ''' -------------------------------------------------------------------------------- /10-Data Analysis With Python/data.csv: -------------------------------------------------------------------------------- 1 | Date,Category,Value,Product,Sales,Region 2 | 2023-01-01,A,28.0,Product1,754.0,East 3 | 2023-01-02,B,39.0,Product3,110.0,North 4 | 2023-01-03,C,32.0,Product2,398.0,East 5 | 2023-01-04,B,8.0,Product1,522.0,East 6 | 2023-01-05,B,26.0,Product3,869.0,North 7 | 2023-01-06,B,54.0,Product3,192.0,West 8 | 2023-01-07,A,16.0,Product1,936.0,East 9 | 2023-01-08,C,89.0,Product1,488.0,West 10 | 2023-01-09,C,37.0,Product3,772.0,West 11 | 2023-01-10,A,22.0,Product2,834.0,West 12 | 2023-01-11,B,7.0,Product1,842.0,North 13 | 2023-01-12,B,60.0,Product2,,West 14 | 2023-01-13,A,70.0,Product3,628.0,South 15 | 2023-01-14,A,69.0,Product1,423.0,East 16 | 2023-01-15,A,47.0,Product2,893.0,West 17 | 2023-01-16,C,,Product1,895.0,North 18 | 2023-01-17,C,93.0,Product2,511.0,South 19 | 2023-01-18,C,,Product1,108.0,West 20 | 2023-01-19,A,31.0,Product2,578.0,West 21 | 2023-01-20,A,59.0,Product1,736.0,East 22 | 2023-01-21,C,82.0,Product3,606.0,South 23 | 2023-01-22,C,37.0,Product2,992.0,South 24 | 2023-01-23,B,62.0,Product3,942.0,North 25 | 2023-01-24,C,92.0,Product2,342.0,West 26 | 2023-01-25,A,24.0,Product2,458.0,East 27 | 2023-01-26,C,95.0,Product1,584.0,West 28 | 2023-01-27,C,71.0,Product2,619.0,North 29 | 2023-01-28,C,56.0,Product2,224.0,North 30 | 2023-01-29,B,,Product3,617.0,North 31 | 2023-01-30,C,51.0,Product2,737.0,South 32 | 2023-01-31,B,50.0,Product3,735.0,West 33 | 2023-02-01,A,17.0,Product2,189.0,West 34 | 2023-02-02,B,63.0,Product3,338.0,South 35 | 2023-02-03,C,27.0,Product3,,East 36 | 2023-02-04,C,70.0,Product3,669.0,West 37 | 2023-02-05,B,60.0,Product2,,West 38 | 2023-02-06,C,36.0,Product3,177.0,East 39 | 2023-02-07,C,2.0,Product1,,North 40 | 2023-02-08,C,94.0,Product1,408.0,South 41 | 2023-02-09,A,62.0,Product1,155.0,West 42 | 2023-02-10,B,15.0,Product1,578.0,East 43 | 2023-02-11,C,97.0,Product1,256.0,East 44 | 2023-02-12,A,93.0,Product3,164.0,West 45 | 2023-02-13,A,43.0,Product3,949.0,East 46 | 2023-02-14,A,96.0,Product3,830.0,East 47 | 2023-02-15,B,99.0,Product2,599.0,West 48 | 2023-02-16,B,6.0,Product1,938.0,South 49 | 2023-02-17,B,69.0,Product3,143.0,West 50 | 2023-02-18,C,65.0,Product3,182.0,North 51 | 2023-02-19,C,11.0,Product3,708.0,North 52 | -------------------------------------------------------------------------------- /10-Data Analysis With Python/data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/10-Data Analysis With Python/data.xlsx -------------------------------------------------------------------------------- /10-Data Analysis With Python/df_excel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/10-Data Analysis With Python/df_excel -------------------------------------------------------------------------------- /10-Data Analysis With Python/sales1_data.csv: -------------------------------------------------------------------------------- 1 | Date,Product,Sales,Region 2 | 2023-01-01,Product3,738.0,West 3 | 2023-01-02,Product2,868.0,North 4 | 2023-01-03,Product2,554.0,West 5 | 2023-01-04,Product1,618.0,South 6 | 2023-01-05,Product3,501.0,East 7 | 2023-01-06,Product1,,West 8 | 2023-01-07,Product3,339.0,South 9 | 2023-01-08,Product3,280.0,South 10 | 2023-01-09,Product2,806.0,North 11 | 2023-01-10,Product2,816.0,South 12 | 2023-01-11,Product3,469.0,West 13 | 2023-01-12,Product3,,East 14 | 2023-01-13,Product3,,East 15 | 2023-01-14,Product3,676.0,East 16 | 2023-01-15,Product1,183.0,South 17 | 2023-01-16,Product1,424.0,South 18 | 2023-01-17,Product1,,South 19 | 2023-01-18,Product1,,South 20 | 2023-01-19,Product2,124.0,North 21 | 2023-01-20,Product3,732.0,West 22 | 2023-01-21,Product2,,West 23 | 2023-01-22,Product3,296.0,West 24 | 2023-01-23,Product2,737.0,West 25 | 2023-01-24,Product3,531.0,East 26 | 2023-01-25,Product2,834.0,North 27 | -------------------------------------------------------------------------------- /10-Data Analysis With Python/sample_data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/10-Data Analysis With Python/sample_data.xlsx -------------------------------------------------------------------------------- /11-Working With Databases/example.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/11-Working With Databases/example.db -------------------------------------------------------------------------------- /11-Working With Databases/sales_data.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/11-Working With Databases/sales_data.db -------------------------------------------------------------------------------- /12-Logging In Python/12.1-logging.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Python Logging\n", 8 | "Logging is a crucial aspect of any application, providing a way to track events, errors, and operational information. Python's built-in logging module offers a flexible framework for emitting log messages from Python programs. In this lesson, we will cover the basics of logging, including how to configure logging, log levels, and best practices for using logging in Python applications." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 3, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "name": "stderr", 18 | "output_type": "stream", 19 | "text": [ 20 | "2024-06-19 12:14:39 - root - DEBUG - This is a debug message\n", 21 | "2024-06-19 12:14:39 - root - INFO - This is an info message\n", 22 | "2024-06-19 12:14:39 - root - WARNING - This is a warning message\n", 23 | "2024-06-19 12:14:39 - root - ERROR - This is an error message\n", 24 | "2024-06-19 12:14:39 - root - CRITICAL - This is a critical message\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "import logging\n", 30 | "\n", 31 | "## Configure the basic logging settings\n", 32 | "logging.basicConfig(level=logging.DEBUG)\n", 33 | "\n", 34 | "## log messages with different severity levels\n", 35 | "logging.debug(\"This is a debug message\")\n", 36 | "logging.info(\"This is an info message\")\n", 37 | "logging.warning(\"This is a warning message\")\n", 38 | "logging.error(\"This is an error message\")\n", 39 | "logging.critical(\"This is a critical message\")\n", 40 | "\n" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "#### Log Levels\n", 48 | "Python's logging module has several log levels indicating the severity of events. The default levels are:\n", 49 | "\n", 50 | "- DEBUG: Detailed information, typically of interest only when diagnosing problems.\n", 51 | "- INFO: Confirmation that things are working as expected.\n", 52 | "- WARNING: An indication that something unexpected happened or indicative of some problem in the near future (e.g., ‘disk space low’). The software is still working as expected.\n", 53 | "- ERROR: Due to a more serious problem, the software has not been able to perform some function.\n", 54 | "- CRITICAL: A very serious error, indicating that the program itself may be unable to continue running." 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 1, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "\n", 64 | "## configuring logging\n", 65 | "import logging\n", 66 | "\n", 67 | "logging.basicConfig(\n", 68 | " filename='app.log',\n", 69 | " filemode='w',\n", 70 | " level=logging.DEBUG,\n", 71 | " format='%(asctime)s-%(name)s-%(levelname)s-%(message)s',\n", 72 | " datefmt='%Y-%m-%d %H:%M:%S'\n", 73 | " )\n", 74 | "\n", 75 | "## log messages with different severity levels\n", 76 | "logging.debug(\"This is a debug message\")\n", 77 | "logging.info(\"This is an info message\")\n", 78 | "logging.warning(\"This is a warning message\")\n", 79 | "logging.error(\"This is an error message\")\n", 80 | "logging.critical(\"This is a critical message\")" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 2, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "logging.debug(\"This is a debug message\")\n", 90 | "logging.info(\"This is an info message\")\n", 91 | "logging.warning(\"This is a warning message\")\n", 92 | "logging.error(\"This is an error message\")\n", 93 | "logging.critical(\"This is a critical message\")" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.12.0" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 2 139 | } 140 | -------------------------------------------------------------------------------- /12-Logging In Python/12.2-multiplelogger.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Logging with Multiple Loggers\n", 8 | "You can create multiple loggers for different parts of your application." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 2, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import logging\n", 18 | "## create a logger for module1\n", 19 | "logger1=logging.getLogger(\"module1\")\n", 20 | "logger1.setLevel(logging.DEBUG)\n", 21 | "\n", 22 | "##create a logger for module 2\n", 23 | "\n", 24 | "logger2=logging.getLogger(\"module2\")\n", 25 | "logger2.setLevel(logging.WARNING)\n", 26 | "\n", 27 | "# Configure logging settings\n", 28 | "logging.basicConfig(\n", 29 | " level=logging.DEBUG,\n", 30 | " format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n", 31 | " datefmt='%Y-%m-%d %H:%M:%S'\n", 32 | ")" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stderr", 42 | "output_type": "stream", 43 | "text": [ 44 | "2024-06-19 13:21:55 - module1 - DEBUG - This is debug message for module1\n", 45 | "2024-06-19 13:21:55 - module2 - WARNING - This is a warning message for module 2\n", 46 | "2024-06-19 13:21:55 - module2 - ERROR - This is an error message\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "## log message with different loggers\n", 52 | "logger1.debug(\"This is debug message for module1\")\n", 53 | "logger2.warning(\"This is a warning message for module 2\")\n", 54 | "logger2.error(\"This is an error message\")" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [] 126 | } 127 | ], 128 | "metadata": { 129 | "kernelspec": { 130 | "display_name": "Python 3", 131 | "language": "python", 132 | "name": "python3" 133 | }, 134 | "language_info": { 135 | "codemirror_mode": { 136 | "name": "ipython", 137 | "version": 3 138 | }, 139 | "file_extension": ".py", 140 | "mimetype": "text/x-python", 141 | "name": "python", 142 | "nbconvert_exporter": "python", 143 | "pygments_lexer": "ipython3", 144 | "version": "3.12.0" 145 | } 146 | }, 147 | "nbformat": 4, 148 | "nbformat_minor": 2 149 | } 150 | -------------------------------------------------------------------------------- /12-Logging In Python/app.log: -------------------------------------------------------------------------------- 1 | 2024-06-19 12:25:46-root-DEBUG-This is a debug message 2 | 2024-06-19 12:25:46-root-INFO-This is an info message 3 | 2024-06-19 12:25:46-root-WARNING-This is a warning message 4 | 2024-06-19 12:25:46-root-ERROR-This is an error message 5 | 2024-06-19 12:25:46-root-CRITICAL-This is a critical message 6 | 2024-06-19 12:26:04-root-DEBUG-This is a debug message 7 | 2024-06-19 12:26:04-root-INFO-This is an info message 8 | 2024-06-19 12:26:04-root-WARNING-This is a warning message 9 | 2024-06-19 12:26:04-root-ERROR-This is an error message 10 | 2024-06-19 12:26:04-root-CRITICAL-This is a critical message 11 | -------------------------------------------------------------------------------- /12-Logging In Python/app.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | ## logging setting 4 | 5 | logging.basicConfig( 6 | level=logging.DEBUG, 7 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 8 | datefmt='%Y-%m-%d %H:%M:%S', 9 | handlers=[ 10 | logging.FileHandler("app1.log"), 11 | logging.StreamHandler() 12 | ] 13 | ) 14 | 15 | logger=logging.getLogger("ArithmethicApp") 16 | 17 | def add(a,b): 18 | result=a+b 19 | logger.debug(f"Adding {a} + {b}= {result}") 20 | return result 21 | 22 | def subtract(a, b): 23 | result = a - b 24 | logger.debug(f"Subtracting {a} - {b} = {result}") 25 | return result 26 | 27 | def multiply(a, b): 28 | result = a * b 29 | logger.debug(f"Multiplying {a} * {b} = {result}") 30 | return result 31 | 32 | def divide(a, b): 33 | try: 34 | result = a / b 35 | logger.debug(f"Dividing {a} / {b} = {result}") 36 | return result 37 | except ZeroDivisionError: 38 | logger.error("Division by zero error") 39 | return None 40 | 41 | add(10,15) 42 | subtract(15,10) 43 | multiply(10,20) 44 | divide(20,0) -------------------------------------------------------------------------------- /12-Logging In Python/app1.log: -------------------------------------------------------------------------------- 1 | 2024-06-19 13:34:00 - ArithmethicApp - DEBUG - Subtracting 15 - 10 = 5 2 | 2024-06-19 13:34:00 - ArithmethicApp - DEBUG - Multiplying 10 * 20 = 200 3 | 2024-06-19 13:34:00 - ArithmethicApp - DEBUG - Dividing 20 / 10 = 2.0 4 | 2024-06-19 13:34:31 - ArithmethicApp - DEBUG - Subtracting 15 - 10 = 5 5 | 2024-06-19 13:34:31 - ArithmethicApp - DEBUG - Multiplying 10 * 20 = 200 6 | 2024-06-19 13:34:31 - ArithmethicApp - DEBUG - Dividing 20 / 10 = 2.0 7 | 2024-06-19 13:35:26 - ArithmethicApp - DEBUG - Adding 10 + 15= 25 8 | 2024-06-19 13:35:26 - ArithmethicApp - DEBUG - Subtracting 15 - 10 = 5 9 | 2024-06-19 13:35:26 - ArithmethicApp - DEBUG - Multiplying 10 * 20 = 200 10 | 2024-06-19 13:35:26 - ArithmethicApp - DEBUG - Dividing 20 / 10 = 2.0 11 | 2024-06-19 13:36:12 - ArithmethicApp - DEBUG - Adding 10 + 15= 25 12 | 2024-06-19 13:36:12 - ArithmethicApp - DEBUG - Subtracting 15 - 10 = 5 13 | 2024-06-19 13:36:12 - ArithmethicApp - DEBUG - Multiplying 10 * 20 = 200 14 | 2024-06-19 13:36:12 - ArithmethicApp - ERROR - Division by zero error 15 | -------------------------------------------------------------------------------- /12-Logging In Python/logs/__pycache__/logger.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/12-Logging In Python/logs/__pycache__/logger.cpython-312.pyc -------------------------------------------------------------------------------- /12-Logging In Python/logs/app.log: -------------------------------------------------------------------------------- 1 | 2024-06-19 12:29:57-root-DEBUG-The addition function is called 2 | 2024-06-19 12:29:57-root-DEBUG-The addition operation is taking place 3 | -------------------------------------------------------------------------------- /12-Logging In Python/logs/logger.py: -------------------------------------------------------------------------------- 1 | ## configuring logging 2 | import logging 3 | 4 | logging.basicConfig( 5 | filename='app.log', 6 | filemode='w', 7 | level=logging.DEBUG, 8 | format='%(asctime)s-%(name)s-%(levelname)s-%(message)s', 9 | datefmt='%Y-%m-%d %H:%M:%S' 10 | ) -------------------------------------------------------------------------------- /12-Logging In Python/logs/test.py: -------------------------------------------------------------------------------- 1 | from logger import logging 2 | 3 | def add(a,b): 4 | logging.debug("The addition operation is taking place") 5 | return a+b 6 | 7 | logging.debug("The addition function is called") 8 | add(10,15) -------------------------------------------------------------------------------- /13-Flask/flask/api.py: -------------------------------------------------------------------------------- 1 | ### Put and Delete-HTTP Verbs 2 | ### Working With API's--Json 3 | 4 | from flask import Flask, jsonify, request 5 | 6 | app = Flask(__name__) 7 | 8 | ##Initial Data in my to do list 9 | items = [ 10 | {"id": 1, "name": "Item 1", "description": "This is item 1"}, 11 | {"id": 2, "name": "Item 2", "description": "This is item 2"} 12 | ] 13 | 14 | @app.route('/') 15 | def home(): 16 | return "Welcome To The Sample To DO List App" 17 | 18 | ## Get: Retrieve all the items 19 | 20 | @app.route('/items',methods=['GET']) 21 | def get_items(): 22 | return jsonify(items) 23 | 24 | ## get: Retireve a specific item by Id 25 | @app.route('/items/',methods=['GET']) 26 | def get_item(item_id): 27 | item=next((item for item in items if item["id"]==item_id),None) 28 | if item is None: 29 | return jsonify({"error":"item not found"}) 30 | return jsonify(item) 31 | 32 | ## Post :create a new task- API 33 | @app.route('/items',methods=['POST']) 34 | def create_item(): 35 | if not request.json or not 'name' in request.json: 36 | return jsonify({"error":"item not found"}) 37 | new_item={ 38 | "id": items[-1]["id"] + 1 if items else 1, 39 | "name":request.json['name'], 40 | "description":request.json["description"] 41 | 42 | 43 | } 44 | items.append(new_item) 45 | return jsonify(new_item) 46 | 47 | # Put: Update an existing item 48 | @app.route('/items/',methods=['PUT']) 49 | def update_item(item_id): 50 | item = next((item for item in items if item["id"] == item_id), None) 51 | if item is None: 52 | return jsonify({"error": "Item not found"}) 53 | item['name'] = request.json.get('name', item['name']) 54 | item['description'] = request.json.get('description', item['description']) 55 | return jsonify(item) 56 | 57 | # DELETE: Delete an item 58 | @app.route('/items/', methods=['DELETE']) 59 | def delete_item(item_id): 60 | global items 61 | items = [item for item in items if item["id"] != item_id] 62 | return jsonify({"result": "Item deleted"}) 63 | 64 | 65 | 66 | 67 | if __name__ == '__main__': 68 | app.run(debug=True) 69 | -------------------------------------------------------------------------------- /13-Flask/flask/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | ''' 3 | It creates an instance of the Flask class, 4 | which will be your WSGI (Web Server Gateway Interface) application. 5 | ''' 6 | ###WSGI Application 7 | app=Flask(__name__) 8 | 9 | @app.route("/") 10 | def welcome(): 11 | return "Welcome to this best Flask course.This should be an amazing course" 12 | 13 | @app.route("/index") 14 | def index(): 15 | return "Welcome to the index page" 16 | 17 | 18 | if __name__=="__main__": 19 | app.run(debug=True) -------------------------------------------------------------------------------- /13-Flask/flask/getpost.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template,request 2 | ''' 3 | It creates an instance of the Flask class, 4 | which will be your WSGI (Web Server Gateway Interface) application. 5 | ''' 6 | ###WSGI Application 7 | app=Flask(__name__) 8 | 9 | @app.route("/") 10 | def welcome(): 11 | return "

Welcome to the flask course

" 12 | 13 | @app.route("/index",methods=['GET']) 14 | def index(): 15 | return render_template('index.html') 16 | 17 | @app.route('/about') 18 | def about(): 19 | return render_template('about.html') 20 | 21 | @app.route('/form',methods=['GET','POST']) 22 | def form(): 23 | if request.method=='POST': 24 | name=request.form['name'] 25 | return f'Hello {name}!' 26 | return render_template('form.html') 27 | 28 | @app.route('/submit',methods=['GET','POST']) 29 | def submit(): 30 | if request.method=='POST': 31 | name=request.form['name'] 32 | return f'Hello {name}!' 33 | return render_template('form.html') 34 | 35 | 36 | if __name__=="__main__": 37 | app.run(debug=True) -------------------------------------------------------------------------------- /13-Flask/flask/jinja.py: -------------------------------------------------------------------------------- 1 | ### Building Url Dynamically 2 | ## Variable Rule 3 | ### Jinja 2 Template Engine 4 | 5 | ### Jinja2 Template Engine 6 | ''' 7 | {{ }} expressions to print output in html 8 | {%...%} conditions, for loops 9 | {#...#} this is for comments 10 | ''' 11 | 12 | from flask import Flask,render_template,request,redirect,url_for 13 | ''' 14 | It creates an instance of the Flask class, 15 | which will be your WSGI (Web Server Gateway Interface) application. 16 | ''' 17 | ###WSGI Application 18 | app=Flask(__name__) 19 | 20 | @app.route("/") 21 | def welcome(): 22 | return "

Welcome to the flask course

" 23 | 24 | @app.route("/index",methods=['GET']) 25 | def index(): 26 | return render_template('index.html') 27 | 28 | @app.route('/about') 29 | def about(): 30 | return render_template('about.html') 31 | 32 | 33 | 34 | ## Variable Rule 35 | @app.route('/success/') 36 | def success(score): 37 | res="" 38 | if score>=50: 39 | res="PASSED" 40 | else: 41 | res="FAILED" 42 | 43 | return render_template('result.html',results=res) 44 | 45 | ## Variable Rule 46 | @app.route('/successres/') 47 | def successres(score): 48 | res="" 49 | if score>=50: 50 | res="PASSED" 51 | else: 52 | res="FAILED" 53 | 54 | exp={'score':score,"res":res} 55 | 56 | return render_template('result1.html',results=exp) 57 | 58 | ## if confition 59 | @app.route('/sucessif/') 60 | def successif(score): 61 | 62 | return render_template('result.html',results=score) 63 | 64 | @app.route('/fail/') 65 | def fail(score): 66 | return render_template('result.html',results=score) 67 | 68 | @app.route('/submit',methods=['POST','GET']) 69 | def submit(): 70 | total_score=0 71 | if request.method=='POST': 72 | science=float(request.form['science']) 73 | maths=float(request.form['maths']) 74 | c=float(request.form['c']) 75 | data_science=float(request.form['datascience']) 76 | 77 | total_score=(science+maths+c+data_science)/4 78 | else: 79 | return render_template('getresult.html') 80 | return redirect(url_for('successres',score=total_score)) 81 | 82 | 83 | 84 | 85 | 86 | 87 | if __name__=="__main__": 88 | app.run(debug=True) 89 | 90 | -------------------------------------------------------------------------------- /13-Flask/flask/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template 2 | ''' 3 | It creates an instance of the Flask class, 4 | which will be your WSGI (Web Server Gateway Interface) application. 5 | ''' 6 | ###WSGI Application 7 | app=Flask(__name__) 8 | 9 | @app.route("/") 10 | def welcome(): 11 | return "

Welcome to the flask course

" 12 | 13 | @app.route("/index") 14 | def index(): 15 | return render_template('index.html') 16 | 17 | @app.route('/about') 18 | def about(): 19 | return render_template('about.html') 20 | 21 | 22 | if __name__=="__main__": 23 | app.run(debug=True) -------------------------------------------------------------------------------- /13-Flask/flask/sample.json: -------------------------------------------------------------------------------- 1 | {"name": "New Item", "description": "This is a new item"} 2 | 3 | {"name": "Updated Item", "description": "This item has been updated"} -------------------------------------------------------------------------------- /13-Flask/flask/templates/about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | About 6 | 7 | 8 |

About

9 |

This is the about page of my Flask app.

10 | 11 | 12 | -------------------------------------------------------------------------------- /13-Flask/flask/templates/form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Form 6 | 7 | 8 |

Submit a Form

9 |
10 | 11 | 12 | 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /13-Flask/flask/templates/getresult.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 |

HTML Forms

13 | 14 |
15 |
16 |
17 |
18 |

19 |
20 |

21 |
22 |

23 | 24 |
25 | 26 |

If you click the "Submit" button, the form-data will be sent to a page called "/submit".

27 | 28 | 29 | -------------------------------------------------------------------------------- /13-Flask/flask/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Flask App 6 | 7 | 8 |

Welcome to My Flask App!

9 |

This is a simple web application built with Flask.

10 | 11 | 12 | -------------------------------------------------------------------------------- /13-Flask/flask/templates/result.html: -------------------------------------------------------------------------------- 1 |

2 | 3 | Based on the marks You have {{ results }} 4 | 5 | {% if results>=50 %} 6 |

You have passed with marks {{results}}

7 | {% else %} 8 |

You have failed with marks {{results}}

9 | {% endif %} 10 | 11 | -------------------------------------------------------------------------------- /13-Flask/flask/templates/result1.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Final Results 4 |

5 | 6 | 7 | 8 | {% for key,value in results.items() %} 9 | 10 | {# This is the comment section #} 11 |

{{ key }}

12 |

{{ value }}

13 | 14 | 15 | {% endfor %} 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /14-Streamlit/app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | import numpy as np 4 | 5 | ## Title of the aplication 6 | st.title("Hello Streamlit") 7 | 8 | ## Diplay a Simple Text 9 | st.write("This is a imple text") 10 | 11 | ##create a simple Dataframe 12 | 13 | df = pd.DataFrame({ 14 | 'first column': [1, 2, 3, 4], 15 | 'second column': [10, 20, 30, 40] 16 | }) 17 | 18 | 19 | ## Display the Dataframe 20 | st.write("Here is the dataframe") 21 | st.write(df) 22 | 23 | 24 | ##create a line chart 25 | 26 | chart_data=pd.DataFrame( 27 | np.random.randn(20,3),columns=['a','b','c'] 28 | ) 29 | st.line_chart(chart_data) -------------------------------------------------------------------------------- /14-Streamlit/classification.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | from sklearn.datasets import load_iris 4 | from sklearn.ensemble import RandomForestClassifier 5 | 6 | @st.cache_data 7 | def load_data(): 8 | iris = load_iris() 9 | df = pd.DataFrame(iris.data, columns=iris.feature_names) 10 | df['species'] = iris.target 11 | return df, iris.target_names 12 | 13 | df,target_names=load_data() 14 | 15 | model=RandomForestClassifier() 16 | model.fit(df.iloc[:,:-1],df['species']) 17 | 18 | st.sidebar.title("Input Features") 19 | sepal_length = st.sidebar.slider("Sepal length", float(df['sepal length (cm)'].min()), float(df['sepal length (cm)'].max())) 20 | sepal_width = st.sidebar.slider("Sepal width", float(df['sepal width (cm)'].min()), float(df['sepal width (cm)'].max())) 21 | petal_length = st.sidebar.slider("Petal length", float(df['petal length (cm)'].min()), float(df['petal length (cm)'].max())) 22 | petal_width = st.sidebar.slider("Petal width", float(df['petal width (cm)'].min()), float(df['petal width (cm)'].max())) 23 | 24 | input_data = [[sepal_length, sepal_width, petal_length, petal_width]] 25 | 26 | ## PRediction 27 | prediction = model.predict(input_data) 28 | predicted_species = target_names[prediction[0]] 29 | 30 | st.write("Prediction") 31 | st.write(f"The predicted species is: {predicted_species}") 32 | 33 | -------------------------------------------------------------------------------- /14-Streamlit/sampledata.csv: -------------------------------------------------------------------------------- 1 | ,Name,Age,City 2 | 0,John,28,New York 3 | 1,Jane,24,Los Angeles 4 | 2,Jake,35,Chicago 5 | 3,Jill,40,Houston 6 | -------------------------------------------------------------------------------- /14-Streamlit/streamlit.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Introduction to Streamlit\n", 8 | "Streamlit is an open-source app framework for Machine Learning and Data Science projects. It allows you to create beautiful web applications for your machine learning and data science projects with simple Python scripts." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": { 15 | "vscode": { 16 | "languageId": "plaintext" 17 | } 18 | }, 19 | "outputs": [], 20 | "source": [] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": { 26 | "vscode": { 27 | "languageId": "plaintext" 28 | } 29 | }, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": { 37 | "vscode": { 38 | "languageId": "plaintext" 39 | } 40 | }, 41 | "outputs": [], 42 | "source": [] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": { 48 | "vscode": { 49 | "languageId": "plaintext" 50 | } 51 | }, 52 | "outputs": [], 53 | "source": [] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": { 59 | "vscode": { 60 | "languageId": "plaintext" 61 | } 62 | }, 63 | "outputs": [], 64 | "source": [] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": { 70 | "vscode": { 71 | "languageId": "plaintext" 72 | } 73 | }, 74 | "outputs": [], 75 | "source": [] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": { 81 | "vscode": { 82 | "languageId": "plaintext" 83 | } 84 | }, 85 | "outputs": [], 86 | "source": [] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": { 92 | "vscode": { 93 | "languageId": "plaintext" 94 | } 95 | }, 96 | "outputs": [], 97 | "source": [] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": { 103 | "vscode": { 104 | "languageId": "plaintext" 105 | } 106 | }, 107 | "outputs": [], 108 | "source": [] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "vscode": { 115 | "languageId": "plaintext" 116 | } 117 | }, 118 | "outputs": [], 119 | "source": [] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": { 125 | "vscode": { 126 | "languageId": "plaintext" 127 | } 128 | }, 129 | "outputs": [], 130 | "source": [] 131 | } 132 | ], 133 | "metadata": { 134 | "language_info": { 135 | "name": "python" 136 | } 137 | }, 138 | "nbformat": 4, 139 | "nbformat_minor": 2 140 | } 141 | -------------------------------------------------------------------------------- /14-Streamlit/widgets.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | 4 | st.title("Streamlit Text Input") 5 | 6 | name=st.text_input("Enter your name:") 7 | 8 | 9 | age=st.slider("Select your age:",0,100,25) 10 | 11 | st.write(f"Your age is {age}.") 12 | 13 | options = ["Python", "Java", "C++", "JavaScript"] 14 | choice = st.selectbox("Choose your favorite language:", options) 15 | st.write(f"You selected {choice}.") 16 | 17 | if name: 18 | st.write(f"Hello, {name}") 19 | 20 | 21 | data = { 22 | "Name": ["John", "Jane", "Jake", "Jill"], 23 | "Age": [28, 24, 35, 40], 24 | "City": ["New York", "Los Angeles", "Chicago", "Houston"] 25 | } 26 | 27 | df = pd.DataFrame(data) 28 | df.to_csv("sampledata.csv") 29 | st.write(df) 30 | 31 | 32 | uploaded_file=st.file_uploader("Choose a CSV file",type="csv") 33 | 34 | if uploaded_file is not None: 35 | df=pd.read_csv(uploaded_file) 36 | st.write(df) 37 | 38 | -------------------------------------------------------------------------------- /16-Multithreading and Multiprocessing/advance_multi_processing.py: -------------------------------------------------------------------------------- 1 | ### Multiprocessing with ProcessPoolExecutor 2 | 3 | from concurrent.futures import ProcessPoolExecutor 4 | import time 5 | 6 | def square_number(number): 7 | time.sleep(2) 8 | return f"Square: {number * number}" 9 | 10 | numbers=[1,2,3,4,5,6,7,8,9,11,2,3,12,14] 11 | if __name__=="__main__": 12 | 13 | with ProcessPoolExecutor(max_workers=3) as executor: 14 | results=executor.map(square_number,numbers) 15 | 16 | for result in results: 17 | print(result) -------------------------------------------------------------------------------- /16-Multithreading and Multiprocessing/advance_multi_threading.py: -------------------------------------------------------------------------------- 1 | ### Multithreading With Thread Pool Executor 2 | 3 | from concurrent.futures import ThreadPoolExecutor 4 | import time 5 | 6 | def print_number(number): 7 | time.sleep(1) 8 | return f"Number :{number}" 9 | 10 | numbers=[1,2,3,4,5,6,7,8,9,0,1,2,3] 11 | 12 | with ThreadPoolExecutor(max_workers=3) as executor: 13 | results=executor.map(print_number,numbers) 14 | 15 | for result in results: 16 | print(result) -------------------------------------------------------------------------------- /16-Multithreading and Multiprocessing/factorial_multi_processing.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Real-World Example: Multiprocessing for CPU-bound Tasks 3 | Scenario: Factorial Calculation 4 | Factorial calculations, especially for large numbers, 5 | involve significant computational work. Multiprocessing 6 | can be used to distribute the workload across multiple 7 | CPU cores, improving performance. 8 | 9 | ''' 10 | 11 | import multiprocessing 12 | import math 13 | import sys 14 | import time 15 | 16 | # Increase the maximum number of digits for integer conversion 17 | sys.set_int_max_str_digits(100000) 18 | 19 | ## function to compute factorials of a given number 20 | 21 | def computer_factorial(number): 22 | print(f"Computing factorial of {number}") 23 | result=math.factorial(number) 24 | print(f"Factorial of {number} is {result}") 25 | return result 26 | 27 | if __name__=="__main__": 28 | numbers=[5000,6000,700,8000] 29 | 30 | start_time=time.time() 31 | 32 | ##create a pool of worker processes 33 | with multiprocessing.Pool() as pool: 34 | results=pool.map(computer_factorial,numbers) 35 | 36 | end_time=time.time() 37 | 38 | print(f"Results: {results}") 39 | print(f"Time taken: {end_time - start_time} seconds") 40 | 41 | -------------------------------------------------------------------------------- /16-Multithreading and Multiprocessing/multi_processing.py: -------------------------------------------------------------------------------- 1 | ## PRocesses that run in parallel 2 | ### CPU-Bound Tasks-Tasks that are heavy on CPU usage (e.g., mathematical computations, data processing). 3 | ## PArallel execution- Multiple cores of the CPU 4 | 5 | import multiprocessing 6 | 7 | import time 8 | 9 | def square_numbers(): 10 | for i in range(5): 11 | time.sleep(1) 12 | print(f"Square: {i*i}") 13 | 14 | def cube_numbers(): 15 | for i in range(5): 16 | time.sleep(1.5) 17 | print(f"Cube: {i * i * i}") 18 | 19 | if __name__=="__main__": 20 | 21 | ## create 2 processes 22 | p1=multiprocessing.Process(target=square_numbers) 23 | p2=multiprocessing.Process(target=cube_numbers) 24 | t=time.time() 25 | 26 | ## start the process 27 | p1.start() 28 | p2.start() 29 | 30 | ## Wait for the process to complete 31 | p1.join() 32 | p2.join() 33 | 34 | finished_time=time.time()-t 35 | print(finished_time) -------------------------------------------------------------------------------- /16-Multithreading and Multiprocessing/multi_threading.py: -------------------------------------------------------------------------------- 1 | ### Multithreading 2 | ## When to use Multi Threading 3 | ###I/O-bound tasks: Tasks that spend more time waiting for I/O operations (e.g., file operations, network requests). 4 | ### Concurrent execution: When you want to improve the throughput of your application by performing multiple operations concurrently. 5 | 6 | import threading 7 | import time 8 | 9 | def print_numbers(): 10 | for i in range(5): 11 | time.sleep(2) 12 | print(f"Number:{i}") 13 | 14 | def print_letter(): 15 | for letter in "abcde": 16 | time.sleep(2) 17 | print(f"Letter: {letter}") 18 | 19 | ##create 2 threads 20 | t1=threading.Thread(target=print_numbers) 21 | t2=threading.Thread(target=print_letter) 22 | 23 | t=time.time() 24 | ## start the thread 25 | t1.start() 26 | t2.start() 27 | 28 | ### Wait for the threads to complete 29 | t1.join() 30 | t2.join() 31 | 32 | finished_time=time.time()-t 33 | print(finished_time) -------------------------------------------------------------------------------- /16-Multithreading and Multiprocessing/webscrapping_multi_threading.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Real-World Example: Multithreading for I/O-bound Tasks 3 | Scenario: Web Scraping 4 | Web scraping often involves making numerous network requests to 5 | fetch web pages. These tasks are I/O-bound because they spend a lot of 6 | time waiting for responses from servers. Multithreading can significantly 7 | improve the performance by allowing multiple web pages to be fetched concurrently. 8 | 9 | ''' 10 | 11 | ''' 12 | 13 | https://python.langchain.com/v0.2/docs/introduction/ 14 | 15 | https://python.langchain.com/v0.2/docs/concepts/ 16 | 17 | https://python.langchain.com/v0.2/docs/tutorials/ 18 | ''' 19 | 20 | import threading 21 | import requests 22 | from bs4 import BeautifulSoup 23 | 24 | urls=[ 25 | 'https://python.langchain.com/v0.2/docs/introduction/', 26 | 27 | 'https://python.langchain.com/v0.2/docs/concepts/', 28 | 29 | 'https://python.langchain.com/v0.2/docs/tutorials/' 30 | 31 | ] 32 | 33 | def fetch_content(url): 34 | response=requests.get(url) 35 | soup=BeautifulSoup(response.content,'html.parser') 36 | print(f'Fetched {len(soup.text)} characters from {url}') 37 | 38 | threads=[] 39 | 40 | for url in urls: 41 | thread=threading.Thread(target=fetch_content,args=(url,)) 42 | threads.append(thread) 43 | thread.start() 44 | 45 | for thread in threads: 46 | thread.join() 47 | 48 | print("All web pages fetched") -------------------------------------------------------------------------------- /2-Control Flow/Conditionalstatements.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Conditional Statements (if, elif, else)\n", 8 | "Video Outline:\n", 9 | "1. Introduction to Conditional Statements\n", 10 | "2. if Statement\n", 11 | "3. else Statement\n", 12 | "4. elif Statement\n", 13 | "5. Nested Conditional Statements\n", 14 | "6. Practical Examples\n", 15 | "7. Common Errors and Best Practices" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "name": "stdout", 25 | "output_type": "stream", 26 | "text": [ 27 | "You are allowed to vote in the elections\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "## if statement\n", 33 | "age=20\n", 34 | "\n", 35 | "if age>=18:\n", 36 | " print(\"You are allowed to vote in the elections\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "True" 48 | ] 49 | }, 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "age>=18" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "You are a minor\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "## else\n", 74 | "## The else statement executes a block of code if the condition in the if statement is False.\n", 75 | "\n", 76 | "age=16\n", 77 | "\n", 78 | "if age>=18:\n", 79 | " print(\"You are eligible for voting\")\n", 80 | "else:\n", 81 | " print(\"You are a minor\")\n", 82 | "\n" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 6, 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "You are a teenager\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "## elif\n", 100 | "## The elif statement allows you to check multiple conditions. It stands for \"else if\"\n", 101 | "\n", 102 | "age=17\n", 103 | "\n", 104 | "if age<13:\n", 105 | " print(\"You are a child\")\n", 106 | "elif age<18:\n", 107 | " print(\"You are a teenager\")\n", 108 | "else:\n", 109 | " print(\"You are an adult\")" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 9, 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "name": "stdout", 119 | "output_type": "stream", 120 | "text": [ 121 | "The number is zero or negative\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "## Nested Condiitonal Statements\n", 127 | "\n", 128 | "# You can place one or more if, elif, or else statements inside another if, elif, or else statement to create nested conditional statements.\n", 129 | "\n", 130 | "## number even ,odd,negative\n", 131 | "\n", 132 | "num=int(input(\"Enter the number\"))\n", 133 | "\n", 134 | "if num>0:\n", 135 | " print(\"The number is positive\")\n", 136 | " if num%2==0:\n", 137 | " print(\"The number is even\")\n", 138 | " else:\n", 139 | " print(\"The number is odd\")\n", 140 | "\n", 141 | "else:\n", 142 | " print(\"The number is zero or negative\")" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 11, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "2024 is a leap year\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "## Practical Examples\n", 160 | "\n", 161 | "## Determine if a year is a leap year using nested condition statement\n", 162 | "\n", 163 | "year=int(input(\"Enter the year\"))\n", 164 | "\n", 165 | "if year%4==0:\n", 166 | " if year%100==0:\n", 167 | " if year%400==0:\n", 168 | " print(year,\"is a leap year\")\n", 169 | " else:\n", 170 | " print(year,\"is not a leap year\")\n", 171 | " else:\n", 172 | " print(year,\"is a leap year\")\n", 173 | "\n", 174 | "else:\n", 175 | " print(year,\"is not a leap year\")\n", 176 | "\n", 177 | "\n" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 12, 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "name": "stdout", 187 | "output_type": "stream", 188 | "text": [ 189 | "Result: 36.0\n" 190 | ] 191 | } 192 | ], 193 | "source": [ 194 | "## Assignment\n", 195 | "## Simple Calculator program\n", 196 | "# Take user input\n", 197 | "num1 = float(input(\"Enter first number: \"))\n", 198 | "num2 = float(input(\"Enter second number: \"))\n", 199 | "operation = input(\"Enter operation (+, -, *, /): \")\n", 200 | "\n", 201 | "# Perform the requested operation\n", 202 | "if operation == '+':\n", 203 | " result = num1 + num2\n", 204 | "elif operation == '-':\n", 205 | " result = num1 - num2\n", 206 | "elif operation == '*':\n", 207 | " result = num1 * num2\n", 208 | "elif operation == '/':\n", 209 | " if num2 != 0:\n", 210 | " result = num1 / num2\n", 211 | " else:\n", 212 | " result = \"Error! Division by zero.\"\n", 213 | "else:\n", 214 | " result = \"Invalid operation.\"\n", 215 | "\n", 216 | "print(\"Result:\", result)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 13, 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [ 225 | "### Determine the ticket price based on age and whether the person is a student.\n", 226 | "# Ticket pricing based on age and student status\n", 227 | "\n", 228 | "# Take user input\n", 229 | "age = int(input(\"Enter your age: \"))\n", 230 | "is_student = input(\"Are you a student? (yes/no): \").lower()\n", 231 | "\n", 232 | "# Determine ticket price\n", 233 | "if age < 5:\n", 234 | " price = \"Free\"\n", 235 | "elif age <= 12:\n", 236 | " price = \"$10\"\n", 237 | "elif age <= 17:\n", 238 | " if is_student == 'yes':\n", 239 | " price = \"$12\"\n", 240 | " else:\n", 241 | " price = \"$15\"\n", 242 | "elif age <= 64:\n", 243 | " if is_student == 'yes':\n", 244 | " price = \"$18\"\n", 245 | " else:\n", 246 | " price = \"$25\"\n", 247 | "else:\n", 248 | " price = \"$20\"\n", 249 | "\n", 250 | "print(\"Ticket Price:\", price)\n", 251 | "\n" 252 | ] 253 | }, 254 | { 255 | "cell_type": "markdown", 256 | "metadata": {}, 257 | "source": [ 258 | "#### Complex Example 3: Employee Bonus Calculation\n", 259 | "\n", 260 | "Calculate an employee's bonus based on their performance rating and years of service." 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [ 269 | "# Employee bonus calculation\n", 270 | "\n", 271 | "# Take user input\n", 272 | "years_of_service = int(input(\"Enter years of service: \"))\n", 273 | "performance_rating = float(input(\"Enter performance rating (1.0 to 5.0): \"))\n", 274 | "\n", 275 | "# Determine bonus percentage\n", 276 | "if performance_rating >= 4.5:\n", 277 | " if years_of_service > 10:\n", 278 | " bonus_percentage = 20\n", 279 | " elif years_of_service > 5:\n", 280 | " bonus_percentage = 15\n", 281 | " else:\n", 282 | " bonus_percentage = 10\n", 283 | "elif performance_rating >= 3.5:\n", 284 | " if years_of_service > 10:\n", 285 | " bonus_percentage = 15\n", 286 | " elif years_of_service > 5:\n", 287 | " bonus_percentage = 10\n", 288 | " else:\n", 289 | " bonus_percentage = 5\n", 290 | "else:\n", 291 | " bonus_percentage = 0\n", 292 | "\n", 293 | "# Calculate bonus amount\n", 294 | "salary = float(input(\"Enter current salary: \"))\n", 295 | "bonus_amount = salary * bonus_percentage / 100\n", 296 | "\n", 297 | "print(\"Bonus Amount: ${:.2f}\".format(bonus_amount))\n" 298 | ] 299 | }, 300 | { 301 | "cell_type": "markdown", 302 | "metadata": {}, 303 | "source": [ 304 | "## Complex Example 4: User Login System\n", 305 | "A simple user login system that checks the username and password." 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 14, 311 | "metadata": {}, 312 | "outputs": [ 313 | { 314 | "name": "stdout", 315 | "output_type": "stream", 316 | "text": [ 317 | "Username not found.\n" 318 | ] 319 | } 320 | ], 321 | "source": [ 322 | "# User login system\n", 323 | "\n", 324 | "# Predefined username and password\n", 325 | "stored_username = \"admin\"\n", 326 | "stored_password = \"password123\"\n", 327 | "\n", 328 | "# Take user input\n", 329 | "username = input(\"Enter username: \")\n", 330 | "password = input(\"Enter password: \")\n", 331 | "\n", 332 | "# Check login credentials\n", 333 | "if username == stored_username:\n", 334 | " if password == stored_password:\n", 335 | " print(\"Login successful!\")\n", 336 | " else:\n", 337 | " print(\"Incorrect password.\")\n", 338 | "else:\n", 339 | " print(\"Username not found.\")\n" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": null, 345 | "metadata": {}, 346 | "outputs": [], 347 | "source": [] 348 | } 349 | ], 350 | "metadata": { 351 | "kernelspec": { 352 | "display_name": "Python 3", 353 | "language": "python", 354 | "name": "python3" 355 | }, 356 | "language_info": { 357 | "codemirror_mode": { 358 | "name": "ipython", 359 | "version": 3 360 | }, 361 | "file_extension": ".py", 362 | "mimetype": "text/x-python", 363 | "name": "python", 364 | "nbconvert_exporter": "python", 365 | "pygments_lexer": "ipython3", 366 | "version": "3.12.0" 367 | } 368 | }, 369 | "nbformat": 4, 370 | "nbformat_minor": 2 371 | } 372 | -------------------------------------------------------------------------------- /2-Control Flow/Loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Loops\n", 8 | "Video Outline:\n", 9 | "1. Introduction to Loops\n", 10 | "2. for Loop\n", 11 | " - Iterating over a range\n", 12 | " - Iterating over a string\n", 13 | "\n", 14 | "3. while Loop\n", 15 | "4. Loop Control Statements\n", 16 | " - break\n", 17 | " - continue\n", 18 | " - pass\n", 19 | "5. Nested Loops\n", 20 | "6. Practical Examples and Common Errors" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "data": { 30 | "text/plain": [ 31 | "range(0, 5)" 32 | ] 33 | }, 34 | "execution_count": 1, 35 | "metadata": {}, 36 | "output_type": "execute_result" 37 | } 38 | ], 39 | "source": [ 40 | "range(5)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "0\n", 53 | "1\n", 54 | "2\n", 55 | "3\n", 56 | "4\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "## for loop\n", 62 | "\n", 63 | "for i in range(5):\n", 64 | " print(i)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stdout", 74 | "output_type": "stream", 75 | "text": [ 76 | "1\n", 77 | "2\n", 78 | "3\n", 79 | "4\n", 80 | "5\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "for i in range(1,6):\n", 86 | " print(i)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 7, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "1\n", 99 | "3\n", 100 | "5\n", 101 | "7\n", 102 | "9\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "for i in range(1,10,2):\n", 108 | " print(i)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 8, 114 | "metadata": {}, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "10\n", 121 | "9\n", 122 | "8\n", 123 | "7\n", 124 | "6\n", 125 | "5\n", 126 | "4\n", 127 | "3\n", 128 | "2\n" 129 | ] 130 | } 131 | ], 132 | "source": [ 133 | "for i in range(10,1,-1):\n", 134 | " print(i)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 9, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "10\n", 147 | "8\n", 148 | "6\n", 149 | "4\n", 150 | "2\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "for i in range(10,1,-2):\n", 156 | " print(i)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 10, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "K\n", 169 | "r\n", 170 | "i\n", 171 | "s\n", 172 | "h\n", 173 | " \n", 174 | "N\n", 175 | "a\n", 176 | "i\n", 177 | "k\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "## strings\n", 183 | "\n", 184 | "str=\"Krish Naik\"\n", 185 | "\n", 186 | "for i in str:\n", 187 | " print(i)" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 11, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "0\n", 200 | "1\n", 201 | "2\n", 202 | "3\n", 203 | "4\n" 204 | ] 205 | } 206 | ], 207 | "source": [ 208 | "## while loop\n", 209 | "\n", 210 | "## The while loop continues to execute as long as the condition is True.\n", 211 | "\n", 212 | "count=0\n", 213 | "\n", 214 | "while count<5:\n", 215 | " print(count)\n", 216 | " count=count+1\n", 217 | "\n", 218 | "\n" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 14, 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "name": "stdout", 228 | "output_type": "stream", 229 | "text": [ 230 | "0\n", 231 | "1\n", 232 | "2\n", 233 | "3\n", 234 | "4\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "## Loop Control Statements\n", 240 | "\n", 241 | "## break\n", 242 | "## The break statement exits the loop permaturely\n", 243 | "\n", 244 | "## break sstatement\n", 245 | "\n", 246 | "for i in range(10):\n", 247 | " if i==5:\n", 248 | " break\n", 249 | " print(i)\n", 250 | " " 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 15, 256 | "metadata": {}, 257 | "outputs": [ 258 | { 259 | "name": "stdout", 260 | "output_type": "stream", 261 | "text": [ 262 | "1\n", 263 | "3\n", 264 | "5\n", 265 | "7\n", 266 | "9\n" 267 | ] 268 | } 269 | ], 270 | "source": [ 271 | "## continue\n", 272 | "\n", 273 | "## The continue statement skips the current iteration and continues with the next.\n", 274 | "\n", 275 | "for i in range(10):\n", 276 | " if i%2==0:\n", 277 | " continue\n", 278 | " print(i)\n", 279 | "\n", 280 | "\n" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": 18, 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "0\n", 293 | "1\n", 294 | "2\n", 295 | "3\n", 296 | "4\n" 297 | ] 298 | } 299 | ], 300 | "source": [ 301 | "## pass\n", 302 | "## The pass statement is a null operation; it does nothing.\n", 303 | "\n", 304 | "for i in range(5):\n", 305 | " if i==3:\n", 306 | " pass\n", 307 | " print(i)\n" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 19, 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "i:0 and j:0\n", 320 | "i:0 and j:1\n", 321 | "i:1 and j:0\n", 322 | "i:1 and j:1\n", 323 | "i:2 and j:0\n", 324 | "i:2 and j:1\n" 325 | ] 326 | } 327 | ], 328 | "source": [ 329 | "## Nested loopss\n", 330 | "## a loop inside a loop\n", 331 | "\n", 332 | "for i in range(3):\n", 333 | " for j in range(2):\n", 334 | " print(f\"i:{i} and j:{j}\")" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 20, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "Sum of first 10 natural number: 55\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "## Examples- Calculate the sum of first N natural numbers using a while and for loop\n", 352 | "\n", 353 | "## while loop \n", 354 | "\n", 355 | "n=10 \n", 356 | "sum=0\n", 357 | "count=1\n", 358 | "\n", 359 | "while count<=n:\n", 360 | " sum=sum+count\n", 361 | " count=count+1\n", 362 | "\n", 363 | "print(\"Sum of first 10 natural number:\",sum)\n" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 21, 369 | "metadata": {}, 370 | "outputs": [ 371 | { 372 | "name": "stdout", 373 | "output_type": "stream", 374 | "text": [ 375 | "55\n" 376 | ] 377 | } 378 | ], 379 | "source": [ 380 | "n=10 \n", 381 | "sum=0\n", 382 | "for i in range(11):\n", 383 | " sum=sum+i\n", 384 | "\n", 385 | "print(sum)" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 22, 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "name": "stdout", 395 | "output_type": "stream", 396 | "text": [ 397 | "2\n", 398 | "3\n", 399 | "5\n", 400 | "7\n", 401 | "11\n", 402 | "13\n", 403 | "17\n", 404 | "19\n", 405 | "23\n", 406 | "29\n", 407 | "31\n", 408 | "37\n", 409 | "41\n", 410 | "43\n", 411 | "47\n", 412 | "53\n", 413 | "59\n", 414 | "61\n", 415 | "67\n", 416 | "71\n", 417 | "73\n", 418 | "79\n", 419 | "83\n", 420 | "89\n", 421 | "97\n" 422 | ] 423 | } 424 | ], 425 | "source": [ 426 | "## Example- Prime numbers between 1 and 100\n", 427 | "\n", 428 | "for num in range(1,101):\n", 429 | " if num>1:\n", 430 | " for i in range(2,num):\n", 431 | " if num%i==0:\n", 432 | " break\n", 433 | " else:\n", 434 | " print(num)" 435 | ] 436 | }, 437 | { 438 | "cell_type": "markdown", 439 | "metadata": {}, 440 | "source": [ 441 | "#### Conclusion:\n", 442 | "Loops are powerful constructs in Python that allow you to execute a block of code multiple times. By understanding and using for and while loops, along with loop control statements like break, continue, and pass, you can handle a wide range of programming tasks efficiently." 443 | ] 444 | }, 445 | { 446 | "cell_type": "code", 447 | "execution_count": null, 448 | "metadata": {}, 449 | "outputs": [], 450 | "source": [] 451 | } 452 | ], 453 | "metadata": { 454 | "kernelspec": { 455 | "display_name": "Python 3", 456 | "language": "python", 457 | "name": "python3" 458 | }, 459 | "language_info": { 460 | "codemirror_mode": { 461 | "name": "ipython", 462 | "version": 3 463 | }, 464 | "file_extension": ".py", 465 | "mimetype": "text/x-python", 466 | "name": "python", 467 | "nbconvert_exporter": "python", 468 | "pygments_lexer": "ipython3", 469 | "version": "3.12.0" 470 | } 471 | }, 472 | "nbformat": 4, 473 | "nbformat_minor": 2 474 | } 475 | -------------------------------------------------------------------------------- /3-Data Structures/3.1.1-ListExamples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Real-World Examples Using Lists in Python\n", 8 | "Lists are one of the most commonly used data structures in Python, thanks to their versatility and ease of use. Here are several practical examples that illustrate their use in real-world scenarios" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "##### Example 1. Manage A To Do List\n", 16 | "- Create a To Do List To Keep Track OF Tasks" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "Don't forgrt to pay the utility bills\n", 29 | "To Do List remaining\n", 30 | "-Buy Groceries\n", 31 | "-Pay bills\n", 32 | "-Schedule meeting\n", 33 | "-Go For a Run\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "to_do_list=[\"Buy Groceries\",\"Clean the house\",\"Pay bills\"]\n", 39 | "\n", 40 | "## Adding to task\n", 41 | "to_do_list.append(\"Schedule meeting\")\n", 42 | "to_do_list.append(\"Go For a Run\")\n", 43 | "\n", 44 | "## Removing a completed task\n", 45 | "to_do_list.remove(\"Clean the house\")\n", 46 | "\n", 47 | "## checking if a task is in the list\n", 48 | "if \"Pay bills\" in to_do_list:\n", 49 | " print(\"Don't forgrt to pay the utility bills\")\n", 50 | "\n", 51 | "print(\"To Do List remaining\")\n", 52 | "for task in to_do_list:\n", 53 | " print(f\"-{task}\")" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "##### Example 2: Organizing Student Grades\n", 61 | "- Create a list to store and calculate average grades for students" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 2, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "Average Grade: 88.00\n", 74 | "Highest Grade: 95\n", 75 | "Lowest Grade: 78\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "# Organizing student grades\n", 81 | "grades = [85, 92, 78, 90, 88]\n", 82 | "\n", 83 | "# Adding a new grade\n", 84 | "grades.append(95)\n", 85 | "\n", 86 | "# Calculating the average grade\n", 87 | "average_grade = sum(grades) / len(grades)\n", 88 | "print(f\"Average Grade: {average_grade:.2f}\")\n", 89 | "\n", 90 | "# Finding the highest and lowest grades\n", 91 | "highest_grade = max(grades)\n", 92 | "lowest_grade = min(grades)\n", 93 | "print(f\"Highest Grade: {highest_grade}\")\n", 94 | "print(f\"Lowest Grade: {lowest_grade}\")\n" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "##### Example 3: Managing An Inventory\n", 102 | "- Use a list to manage inventory items in a store" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 3, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "oranges are in stock.\n", 115 | "Inventory List:\n", 116 | "- apples\n", 117 | "- oranges\n", 118 | "- grapes\n", 119 | "- strawberries\n" 120 | ] 121 | } 122 | ], 123 | "source": [ 124 | "# Managing an inventory\n", 125 | "inventory = [\"apples\", \"bananas\", \"oranges\", \"grapes\"]\n", 126 | "\n", 127 | "# Adding a new item\n", 128 | "inventory.append(\"strawberries\")\n", 129 | "\n", 130 | "# Removing an item that is out of stock\n", 131 | "inventory.remove(\"bananas\")\n", 132 | "\n", 133 | "# Checking if an item is in stock\n", 134 | "item = \"oranges\"\n", 135 | "if item in inventory:\n", 136 | " print(f\"{item} are in stock.\")\n", 137 | "else:\n", 138 | " print(f\"{item} are out of stock.\")\n", 139 | "\n", 140 | "# Printing the inventory\n", 141 | "print(\"Inventory List:\")\n", 142 | "for item in inventory:\n", 143 | " print(f\"- {item}\")\n" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "##### Example 4:Collecting User Feedback\n", 151 | "- Use a list to collect and analyze user feedback." 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 4, 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | "Positive Feedback Count: 2\n", 164 | "User Feedback:\n", 165 | "- Great service!\n", 166 | "- Very satisfied\n", 167 | "- Could be better\n", 168 | "- Excellent experience\n", 169 | "- Not happy with the service\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "# Collecting user feedback\n", 175 | "feedback = [\"Great service!\", \"Very satisfied\", \"Could be better\", \"Excellent experience\"]\n", 176 | "\n", 177 | "# Adding new feedback\n", 178 | "feedback.append(\"Not happy with the service\")\n", 179 | "\n", 180 | "# Counting specific feedback\n", 181 | "positive_feedback_count = sum(1 for comment in feedback if \"great\" in comment.lower() or \"excellent\" in comment.lower())\n", 182 | "print(f\"Positive Feedback Count: {positive_feedback_count}\")\n", 183 | "\n", 184 | "# Printing all feedback\n", 185 | "print(\"User Feedback:\")\n", 186 | "for comment in feedback:\n", 187 | " print(f\"- {comment}\")\n" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [] 196 | } 197 | ], 198 | "metadata": { 199 | "kernelspec": { 200 | "display_name": "Python 3", 201 | "language": "python", 202 | "name": "python3" 203 | }, 204 | "language_info": { 205 | "codemirror_mode": { 206 | "name": "ipython", 207 | "version": 3 208 | }, 209 | "file_extension": ".py", 210 | "mimetype": "text/x-python", 211 | "name": "python", 212 | "nbconvert_exporter": "python", 213 | "pygments_lexer": "ipython3", 214 | "version": "3.12.0" 215 | } 216 | }, 217 | "nbformat": 4, 218 | "nbformat_minor": 2 219 | } 220 | -------------------------------------------------------------------------------- /4-Functions/4.1-functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Functions in Python\n", 8 | "Video Outline:\n", 9 | "1. Introduction to Functions\n", 10 | "2. Defining Functions\n", 11 | "3. Calling Functions\n", 12 | "4. Function Parameters\n", 13 | "5. Default Parameters\n", 14 | "6. Variable-Length Arguments\n", 15 | "7. Return Statement" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "##### Introduction to Functions\n", 23 | "Definition:\n", 24 | "\n", 25 | "A function is a block of code that performs a specific task.\n", 26 | "Functions help in organizing code, reusing code, and improving readability.\n", 27 | "\n" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "## syntax\n", 37 | "def function_name(parameters):\n", 38 | " \"\"\"Docstring\"\"\"\n", 39 | " # Function body\n", 40 | " return expression\n" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "the number is even\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "## why functions?\n", 58 | "num=24\n", 59 | "if num%2==0:\n", 60 | " print(\"the number is even\")\n", 61 | "else:\n", 62 | " print(\"the number is odd\")" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 5, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "def even_or_odd(num):\n", 72 | " \"\"\"This function finds even or odd\"\"\"\n", 73 | " if num%2==0:\n", 74 | " print(\"the number is even\")\n", 75 | " else:\n", 76 | " print(\"the number is odd\")\n" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 6, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "the number is even\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "## Call this function\n", 94 | "even_or_odd(24)" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 7, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "6\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "## function with multiple parameters\n", 112 | "\n", 113 | "def add(a,b):\n", 114 | " return a+b\n", 115 | "\n", 116 | "result=add(2,4)\n", 117 | "print(result)\n", 118 | " " 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 9, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Hello Krish Welcome To the paradise\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "## Default Parameters\n", 136 | "\n", 137 | "def greet(name):\n", 138 | " print(f\"Hello {name} Welcome To the paradise\")\n", 139 | "\n", 140 | "greet(\"Krish\")\n" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 12, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "Hello Krish Welcome To the paradise\n" 153 | ] 154 | } 155 | ], 156 | "source": [ 157 | "def greet(name=\"Guest\"):\n", 158 | " print(f\"Hello {name} Welcome To the paradise\")\n", 159 | "\n", 160 | "greet(\"Krish\")" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 13, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "### Variable Length Arguments\n", 170 | "## Positional And Keywords arguments\n", 171 | "\n", 172 | "def print_numbers(*krish):\n", 173 | " for number in krish:\n", 174 | " print(number)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 14, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "1\n", 187 | "2\n", 188 | "3\n", 189 | "4\n", 190 | "5\n", 191 | "6\n", 192 | "7\n", 193 | "8\n", 194 | "Krish\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "print_numbers(1,2,3,4,5,6,7,8,\"Krish\")" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 15, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "## Positional arguments\n", 209 | "def print_numbers(*args):\n", 210 | " for number in args:\n", 211 | " print(number)" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 16, 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "1\n", 224 | "2\n", 225 | "3\n", 226 | "4\n", 227 | "5\n", 228 | "6\n", 229 | "7\n", 230 | "8\n", 231 | "Krish\n" 232 | ] 233 | } 234 | ], 235 | "source": [ 236 | "print_numbers(1,2,3,4,5,6,7,8,\"Krish\")" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 17, 242 | "metadata": {}, 243 | "outputs": [], 244 | "source": [ 245 | "### Keywords Arguments\n", 246 | "\n", 247 | "def print_details(**kwargs):\n", 248 | " for key,value in kwargs.items():\n", 249 | " print(f\"{key}:{value}\")" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": 18, 255 | "metadata": {}, 256 | "outputs": [ 257 | { 258 | "name": "stdout", 259 | "output_type": "stream", 260 | "text": [ 261 | "name:Krish\n", 262 | "age:32\n", 263 | "country:India\n" 264 | ] 265 | } 266 | ], 267 | "source": [ 268 | "print_details(name=\"Krish\",age=\"32\",country=\"India\")" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 19, 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [ 277 | "def print_details(*args,**kwargs):\n", 278 | " for val in args:\n", 279 | " print(f\" Positional arument :{val}\")\n", 280 | " \n", 281 | " for key,value in kwargs.items():\n", 282 | " print(f\"{key}:{value}\")" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 20, 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "name": "stdout", 292 | "output_type": "stream", 293 | "text": [ 294 | " Positional arument :1\n", 295 | " Positional arument :2\n", 296 | " Positional arument :3\n", 297 | " Positional arument :4\n", 298 | " Positional arument :Krish\n", 299 | "name:Krish\n", 300 | "age:32\n", 301 | "country:India\n" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "print_details(1,2,3,4,\"Krish\",name=\"Krish\",age=\"32\",country=\"India\")" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 21, 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "data": { 316 | "text/plain": [ 317 | "6" 318 | ] 319 | }, 320 | "execution_count": 21, 321 | "metadata": {}, 322 | "output_type": "execute_result" 323 | } 324 | ], 325 | "source": [ 326 | "### Return statements\n", 327 | "def multiply(a,b):\n", 328 | " return a*b\n", 329 | "\n", 330 | "multiply(2,3)" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 22, 336 | "metadata": {}, 337 | "outputs": [ 338 | { 339 | "data": { 340 | "text/plain": [ 341 | "(6, 2)" 342 | ] 343 | }, 344 | "execution_count": 22, 345 | "metadata": {}, 346 | "output_type": "execute_result" 347 | } 348 | ], 349 | "source": [ 350 | "### Return multiple parameters\n", 351 | "def multiply(a,b):\n", 352 | " return a*b,a\n", 353 | "\n", 354 | "multiply(2,3)" 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "execution_count": null, 360 | "metadata": {}, 361 | "outputs": [], 362 | "source": [] 363 | } 364 | ], 365 | "metadata": { 366 | "kernelspec": { 367 | "display_name": "Python 3", 368 | "language": "python", 369 | "name": "python3" 370 | }, 371 | "language_info": { 372 | "codemirror_mode": { 373 | "name": "ipython", 374 | "version": 3 375 | }, 376 | "file_extension": ".py", 377 | "mimetype": "text/x-python", 378 | "name": "python", 379 | "nbconvert_exporter": "python", 380 | "pygments_lexer": "ipython3", 381 | "version": "3.12.0" 382 | } 383 | }, 384 | "nbformat": 4, 385 | "nbformat_minor": 2 386 | } 387 | -------------------------------------------------------------------------------- /4-Functions/4.2-examplesfunctions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Functions Examples\n" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#### Example 1: Temperature Conversion" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "77.0\n", 27 | "25.0\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "def convert_temperature(temp,unit):\n", 33 | " \"\"\"This function converts temperature between Celsius and Fahrenheit\"\"\"\n", 34 | " if unit=='C':\n", 35 | " return temp * 9/5 + 32 ## Celsius To Fahrenheit\n", 36 | " elif unit==\"F\":\n", 37 | " return (temp-32)*5/9 ## Fahrenheit to celsius\n", 38 | " else:\n", 39 | " return None\n", 40 | "\n", 41 | "print(convert_temperature(25,'C'))\n", 42 | "print(convert_temperature(77,'F'))" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "##### Example 2: Password Strength Checker" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "False\n", 62 | "True\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "def is_strong_password(password):\n", 68 | " \"\"\"This function checks if the password is strong or not\"\"\"\n", 69 | " if len(password)<8:\n", 70 | " return False\n", 71 | " if not any(char.isdigit() for char in password):\n", 72 | " return False\n", 73 | " if not any(char.islower() for char in password):\n", 74 | " return False\n", 75 | " if not any(char.isupper() for char in password):\n", 76 | " return False\n", 77 | " if not any(char in '!@#$%^&*()_+' for char in password):\n", 78 | " return False\n", 79 | " return True\n", 80 | "\n", 81 | "## calling the function\n", 82 | "print(is_strong_password(\"WeakPwd\"))\n", 83 | "print(is_strong_password(\"Str0ngPwd!\"))\n", 84 | " \n", 85 | " " 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "##### Example 3: Calculate the Total Cost Of Items In a Shopping Cart" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 4, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "5.8999999999999995\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "def calculate_total_cost(cart):\n", 110 | " total_cost=0\n", 111 | " for item in cart:\n", 112 | " total_cost+=item['price']* item['quantity']\n", 113 | "\n", 114 | " return total_cost\n", 115 | "\n", 116 | "\n", 117 | "## Example cart data\n", 118 | "\n", 119 | "cart=[\n", 120 | " {'name':'Apple','price':0.5,'quantity':4},\n", 121 | " {'name':'Banana','price':0.3,'quantity':6},\n", 122 | " {'name':'Orange','price':0.7,'quantity':3}\n", 123 | "\n", 124 | "]\n", 125 | "\n", 126 | "## calling the function\n", 127 | "total_cost=calculate_total_cost(cart)\n", 128 | "print(total_cost)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "##### Example 4: Check IF a String Is Palindrome" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 5, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "True\n", 148 | "False\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "def is_palindrome(s):\n", 154 | " s=s.lower().replace(\" \",\"\")\n", 155 | " return s==s[::-1]\n", 156 | "\n", 157 | "print(is_palindrome(\"A man a plan a canal Panama\"))\n", 158 | "print(is_palindrome(\"Hello\"))" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "metadata": {}, 164 | "source": [ 165 | "##### Example 5: Calculate the factorials of a number using recursion" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 7, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "720\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "def factorial(n):\n", 183 | " if n==0:\n", 184 | " return 1\n", 185 | " else:\n", 186 | " return n * factorial(n-1)\n", 187 | " \n", 188 | "print(factorial(6))" 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "metadata": {}, 194 | "source": [ 195 | "##### Example 6: A Function To Read A File and count the frequency of each word" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 10, 201 | "metadata": {}, 202 | "outputs": [ 203 | { 204 | "name": "stdout", 205 | "output_type": "stream", 206 | "text": [ 207 | "{'hello': 1, 'world': 1, 'how': 1, 'are': 1, 'you': 1, 'my': 1, 'name': 1, 'is': 1, 'krish': 2}\n" 208 | ] 209 | } 210 | ], 211 | "source": [ 212 | "def count_word_frequency(file_path):\n", 213 | " word_count={}\n", 214 | " with open(file_path,'r') as file:\n", 215 | " for line in file:\n", 216 | " words=line.split()\n", 217 | " for word in words:\n", 218 | " word=word.lower().strip('.,!?;:\"\\'')\n", 219 | " word_count[word]=word_count.get(word,0)+1\n", 220 | " \n", 221 | " return word_count\n", 222 | "\n", 223 | "filepath='sample.txt'\n", 224 | "word_frequency=count_word_frequency(filepath)\n", 225 | "print(word_frequency)\n" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "##### Example 7: Validate Email Address" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 11, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "True\n", 245 | "False\n" 246 | ] 247 | } 248 | ], 249 | "source": [ 250 | "import re\n", 251 | "\n", 252 | "# Email validation function\n", 253 | "def is_valid_email(email):\n", 254 | " \"\"\"This function checks if the email is valid.\"\"\"\n", 255 | " pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$'\n", 256 | " return re.match(pattern, email) is not None\n", 257 | "\n", 258 | "# Calling the function\n", 259 | "print(is_valid_email(\"test@example.com\")) # Output: True\n", 260 | "print(is_valid_email(\"invalid-email\")) # Output: False\n" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [] 269 | } 270 | ], 271 | "metadata": { 272 | "kernelspec": { 273 | "display_name": "Python 3", 274 | "language": "python", 275 | "name": "python3" 276 | }, 277 | "language_info": { 278 | "codemirror_mode": { 279 | "name": "ipython", 280 | "version": 3 281 | }, 282 | "file_extension": ".py", 283 | "mimetype": "text/x-python", 284 | "name": "python", 285 | "nbconvert_exporter": "python", 286 | "pygments_lexer": "ipython3", 287 | "version": "3.12.0" 288 | } 289 | }, 290 | "nbformat": 4, 291 | "nbformat_minor": 2 292 | } 293 | -------------------------------------------------------------------------------- /4-Functions/4.3-Lambda.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "##### Lambda Functions in Python\n", 8 | "Lambda functions are small anonymous functions defined using the **lambda** keyword. They can have any number of arguments but only one expression. They are commonly used for short operations or as arguments to higher-order functions.\n", 9 | "\n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "#Syntax\n", 19 | "lambda arguments: expression\n" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 2, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "def addition(a,b):\n", 29 | " return a+b" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 3, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "data": { 39 | "text/plain": [ 40 | "5" 41 | ] 42 | }, 43 | "execution_count": 3, 44 | "metadata": {}, 45 | "output_type": "execute_result" 46 | } 47 | ], 48 | "source": [ 49 | "addition(2,3)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 5, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "11\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "addition=lambda a,b:a+b\n", 67 | "type(addition)\n", 68 | "print(addition(5,6))" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 6, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "data": { 78 | "text/plain": [ 79 | "True" 80 | ] 81 | }, 82 | "execution_count": 6, 83 | "metadata": {}, 84 | "output_type": "execute_result" 85 | } 86 | ], 87 | "source": [ 88 | "def even(num):\n", 89 | " if num%2==0:\n", 90 | " return True\n", 91 | " \n", 92 | "even(24)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 7, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "data": { 102 | "text/plain": [ 103 | "True" 104 | ] 105 | }, 106 | "execution_count": 7, 107 | "metadata": {}, 108 | "output_type": "execute_result" 109 | } 110 | ], 111 | "source": [ 112 | "even1=lambda num:num%2==0\n", 113 | "even1(12)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 8, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "39" 125 | ] 126 | }, 127 | "execution_count": 8, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "def addition(x,y,z):\n", 134 | " return x+y+z\n", 135 | "\n", 136 | "addition(12,13,14)" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 9, 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "39" 148 | ] 149 | }, 150 | "execution_count": 9, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "addition1=lambda x,y,z:x+y+z\n", 157 | "addition1(12,13,14)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 10, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "data": { 167 | "text/plain": [ 168 | "4" 169 | ] 170 | }, 171 | "execution_count": 10, 172 | "metadata": {}, 173 | "output_type": "execute_result" 174 | } 175 | ], 176 | "source": [ 177 | "## map()- applies a function to all items in a list\n", 178 | "numbers=[1,2,3,4,5,6]\n", 179 | "def square(number):\n", 180 | " return number**2\n", 181 | "\n", 182 | "square(2)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 12, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "[1, 4, 9, 16, 25, 36]" 194 | ] 195 | }, 196 | "execution_count": 12, 197 | "metadata": {}, 198 | "output_type": "execute_result" 199 | } 200 | ], 201 | "source": [ 202 | "list(map(lambda x:x**2,numbers))" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": null, 208 | "metadata": {}, 209 | "outputs": [], 210 | "source": [] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [] 225 | } 226 | ], 227 | "metadata": { 228 | "kernelspec": { 229 | "display_name": "Python 3", 230 | "language": "python", 231 | "name": "python3" 232 | }, 233 | "language_info": { 234 | "codemirror_mode": { 235 | "name": "ipython", 236 | "version": 3 237 | }, 238 | "file_extension": ".py", 239 | "mimetype": "text/x-python", 240 | "name": "python", 241 | "nbconvert_exporter": "python", 242 | "pygments_lexer": "ipython3", 243 | "version": "3.12.0" 244 | } 245 | }, 246 | "nbformat": 4, 247 | "nbformat_minor": 2 248 | } 249 | -------------------------------------------------------------------------------- /4-Functions/4.4-Mapsfunction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### The map() Function in Python\n", 8 | "The map() function applies a given function to all items in an input list (or any other iterable) and returns a map object (an iterator). This is particularly useful for transforming data in a list comprehensively." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 2, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "data": { 18 | "text/plain": [ 19 | "100" 20 | ] 21 | }, 22 | "execution_count": 2, 23 | "metadata": {}, 24 | "output_type": "execute_result" 25 | } 26 | ], 27 | "source": [ 28 | "def square(x):\n", 29 | " return x*x\n", 30 | "\n", 31 | "square(10)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 5, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "data": { 41 | "text/plain": [ 42 | "[1, 4, 9, 16, 25, 36, 49, 64]" 43 | ] 44 | }, 45 | "execution_count": 5, 46 | "metadata": {}, 47 | "output_type": "execute_result" 48 | } 49 | ], 50 | "source": [ 51 | "numbers=[1,2,3,4,5,6,7,8]\n", 52 | "\n", 53 | "list(map(square,numbers))\n" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 6, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "data": { 63 | "text/plain": [ 64 | "[1, 4, 9, 16, 25, 36, 49, 64]" 65 | ] 66 | }, 67 | "execution_count": 6, 68 | "metadata": {}, 69 | "output_type": "execute_result" 70 | } 71 | ], 72 | "source": [ 73 | "## Lambda function with map\n", 74 | "numbers=[1,2,3,4,5,6,7,8]\n", 75 | "list(map(lambda x:x*x,numbers))" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 7, 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "[5, 7, 9]\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "### MAp multiple iterables\n", 93 | "\n", 94 | "numbers1=[1,2,3]\n", 95 | "numbers2=[4,5,6]\n", 96 | "\n", 97 | "added_numbers=list(map(lambda x,y:x+y,numbers1,numbers2))\n", 98 | "print(added_numbers)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 8, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "[1, 2, 3, 4, 5]\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "## map() to convert a list of strings to integers\n", 116 | "# Use map to convert strings to integers\n", 117 | "str_numbers = ['1', '2', '3', '4', '5']\n", 118 | "int_numbers = list(map(int, str_numbers))\n", 119 | "\n", 120 | "print(int_numbers) # Output: [1, 2, 3, 4, 5]\n" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 9, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "['APPLE', 'BANANA', 'CHERRY']\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "words=['apple','banana','cherry']\n", 138 | "upper_word=list(map(str.upper,words))\n", 139 | "print(upper_word)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 10, 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "data": { 149 | "text/plain": [ 150 | "['Krish', 'Jack']" 151 | ] 152 | }, 153 | "execution_count": 10, 154 | "metadata": {}, 155 | "output_type": "execute_result" 156 | } 157 | ], 158 | "source": [ 159 | "def get_name(person):\n", 160 | " return person['name']\n", 161 | "\n", 162 | "people=[\n", 163 | " {'name':'Krish','age':32},\n", 164 | " {'name':'Jack','age':33}\n", 165 | "]\n", 166 | "list(map(get_name,people))\n", 167 | "\n" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": {}, 173 | "source": [ 174 | "#### Conclusion\n", 175 | "The map() function is a powerful tool for applying transformations to iterable data structures. It can be used with regular functions, lambda functions, and even multiple iterables, providing a versatile approach to data processing in Python. By understanding and utilizing map(), you can write more efficient and readable code." 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": null, 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [] 184 | } 185 | ], 186 | "metadata": { 187 | "kernelspec": { 188 | "display_name": "Python 3", 189 | "language": "python", 190 | "name": "python3" 191 | }, 192 | "language_info": { 193 | "codemirror_mode": { 194 | "name": "ipython", 195 | "version": 3 196 | }, 197 | "file_extension": ".py", 198 | "mimetype": "text/x-python", 199 | "name": "python", 200 | "nbconvert_exporter": "python", 201 | "pygments_lexer": "ipython3", 202 | "version": "3.12.0" 203 | } 204 | }, 205 | "nbformat": 4, 206 | "nbformat_minor": 2 207 | } 208 | -------------------------------------------------------------------------------- /4-Functions/4.5-filterfunction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "##### The filter() Function in Python\n", 8 | "The filter() function constructs an iterator from elements of an iterable for which a function returns true. It is used to filter out items from a list (or any other iterable) based on a condition." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "def even(num):\n", 18 | " if num%2==0:\n", 19 | " return True" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 2, 25 | "metadata": {}, 26 | "outputs": [ 27 | { 28 | "data": { 29 | "text/plain": [ 30 | "True" 31 | ] 32 | }, 33 | "execution_count": 2, 34 | "metadata": {}, 35 | "output_type": "execute_result" 36 | } 37 | ], 38 | "source": [ 39 | "even(24)" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 3, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "data": { 49 | "text/plain": [ 50 | "[2, 4, 6, 8, 10, 12]" 51 | ] 52 | }, 53 | "execution_count": 3, 54 | "metadata": {}, 55 | "output_type": "execute_result" 56 | } 57 | ], 58 | "source": [ 59 | "lst=[1,2,3,4,5,6,7,8,9,10,11,12]\n", 60 | "\n", 61 | "list(filter(even,lst))\n" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 4, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "[6, 7, 8, 9]\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "## filter with a Lambda Function\n", 79 | "numbers=[1,2,3,4,5,6,7,8,9]\n", 80 | "greater_than_five=list(filter(lambda x:x>5,numbers))\n", 81 | "print(greater_than_five)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "[6, 8]\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "## Filter with a lambda function and multiple conditions\n", 99 | "numbers=[1,2,3,4,5,6,7,8,9]\n", 100 | "even_and_greater_than_five=list(filter(lambda x:x>5 and x%2==0,numbers))\n", 101 | "print(even_and_greater_than_five)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 6, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "[{'name': 'Krish', 'age': 32}, {'name': 'Jack', 'age': 33}]" 113 | ] 114 | }, 115 | "execution_count": 6, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "## Filter() to check if the age is greate than 25 in dictionaries\n", 122 | "people=[\n", 123 | " {'name':'Krish','age':32},\n", 124 | " {'name':'Jack','age':33},\n", 125 | " {'name':'John','age':25}\n", 126 | "]\n", 127 | "\n", 128 | "def age_greater_than_25(person):\n", 129 | " return person['age']>25\n", 130 | "\n", 131 | "list(filter(age_greater_than_25,people))" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "##### Conclusion\n", 139 | "The filter() function is a powerful tool for creating iterators that filter items out of an iterable based on a function. It is commonly used for data cleaning, filtering objects, and removing unwanted elements from lists. By mastering filter(), you can write more concise and efficient code for processing and manipulating collections in Python." 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": {}, 145 | "source": [] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [] 174 | } 175 | ], 176 | "metadata": { 177 | "kernelspec": { 178 | "display_name": "Python 3", 179 | "language": "python", 180 | "name": "python3" 181 | }, 182 | "language_info": { 183 | "codemirror_mode": { 184 | "name": "ipython", 185 | "version": 3 186 | }, 187 | "file_extension": ".py", 188 | "mimetype": "text/x-python", 189 | "name": "python", 190 | "nbconvert_exporter": "python", 191 | "pygments_lexer": "ipython3", 192 | "version": "3.12.0" 193 | } 194 | }, 195 | "nbformat": 4, 196 | "nbformat_minor": 2 197 | } 198 | -------------------------------------------------------------------------------- /4-Functions/sample.txt: -------------------------------------------------------------------------------- 1 | Hello World How are you 2 | My name is Krish KRish -------------------------------------------------------------------------------- /5-Modules/5.1-import.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "##### Importing Modules in Python: Modules and Packages\n", 8 | "In Python, modules and packages help organize and reuse code. Here's a comprehensive guide on how to import them." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "data": { 18 | "text/plain": [ 19 | "4.0" 20 | ] 21 | }, 22 | "execution_count": 1, 23 | "metadata": {}, 24 | "output_type": "execute_result" 25 | } 26 | ], 27 | "source": [ 28 | "import math\n", 29 | "math.sqrt(16)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "4.0\n", 42 | "5.0\n", 43 | "3.141592653589793\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "from math import sqrt,pi\n", 49 | "print(sqrt(16))\n", 50 | "print(sqrt(25))\n", 51 | "print(pi)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 5, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "array([1, 2, 3, 4])" 63 | ] 64 | }, 65 | "execution_count": 5, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "import numpy as np\n", 72 | "np.array([1,2,3,4])" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 7, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "name": "stdout", 82 | "output_type": "stream", 83 | "text": [ 84 | "4.0\n", 85 | "3.141592653589793\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "from math import *\n", 91 | "print(sqrt(16))\n", 92 | "print(pi)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 14, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "data": { 102 | "text/plain": [ 103 | "5" 104 | ] 105 | }, 106 | "execution_count": 14, 107 | "metadata": {}, 108 | "output_type": "execute_result" 109 | } 110 | ], 111 | "source": [ 112 | "from package.maths import addition\n", 113 | "addition(2,3)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 23, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "5" 125 | ] 126 | }, 127 | "execution_count": 23, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "from package import maths\n", 134 | "maths.addition(2,3)\n" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "#### Conclusion\n", 142 | "Importing modules and packages in Python allows you to organize your code, reuse functionalities, and keep your projects clean and manageable. By understanding how to import modules, specific functions, and use relative imports within packages, you can structure your Python applications more effectively." 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [] 149 | } 150 | ], 151 | "metadata": { 152 | "kernelspec": { 153 | "display_name": "Python 3", 154 | "language": "python", 155 | "name": "python3" 156 | }, 157 | "language_info": { 158 | "codemirror_mode": { 159 | "name": "ipython", 160 | "version": 3 161 | }, 162 | "file_extension": ".py", 163 | "mimetype": "text/x-python", 164 | "name": "python", 165 | "nbconvert_exporter": "python", 166 | "pygments_lexer": "ipython3", 167 | "version": "3.12.0" 168 | } 169 | }, 170 | "nbformat": 4, 171 | "nbformat_minor": 2 172 | } 173 | -------------------------------------------------------------------------------- /5-Modules/5.2-Standardlibrary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "##### Standard Library Overview\n", 8 | "Python's Standard Library is a vast collection of modules and packages that come bundled with Python, providing a wide range of functionalities out of the box. Here's an overview of some of the most commonly used modules and packages in the Python Standard Library." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "name": "stdout", 18 | "output_type": "stream", 19 | "text": [ 20 | "array('i', [1, 2, 3, 4])\n" 21 | ] 22 | } 23 | ], 24 | "source": [ 25 | "import array\n", 26 | "arr=array.array('i',[1,2,3,4])\n", 27 | "print(arr)" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 2, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "4.0\n", 40 | "3.141592653589793\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "import math\n", 46 | "print(math.sqrt(16))\n", 47 | "print(math.pi)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 6, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "2\n", 60 | "cherry\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "## random \n", 66 | "\n", 67 | "import random\n", 68 | "print(random.randint(1,10))\n", 69 | "print(random.choice(['apple','banana','cherry']))" 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 | "e:\\UDemy Final\\python\\5-Modules\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "### File And Directory Access\n", 87 | "\n", 88 | "import os\n", 89 | "print(os.getcwd())" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 8, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "os.mkdir('test_dir')" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 9, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "data": { 108 | "text/plain": [ 109 | "'destination.txt'" 110 | ] 111 | }, 112 | "execution_count": 9, 113 | "metadata": {}, 114 | "output_type": "execute_result" 115 | } 116 | ], 117 | "source": [ 118 | "## High level operations on files and collection of files\n", 119 | "import shutil\n", 120 | "shutil.copyfile('source.txt','destination.txt')" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 10, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "{\"name\": \"Krish\", \"age\": 25}\n", 133 | "\n", 134 | "{'name': 'Krish', 'age': 25}\n", 135 | "\n" 136 | ] 137 | } 138 | ], 139 | "source": [ 140 | "## Data Serialization\n", 141 | "import json\n", 142 | "data={'name':'Krish','age':25}\n", 143 | "\n", 144 | "json_str=json.dumps(data)\n", 145 | "print(json_str)\n", 146 | "print(type(json_str))\n", 147 | "\n", 148 | "parsed_data=json.loads(json_str)\n", 149 | "print(parsed_data)\n", 150 | "print(type(parsed_data))\n" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 11, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "['name', 'age']\n", 163 | "['Krish', '32']\n" 164 | ] 165 | } 166 | ], 167 | "source": [ 168 | "## csv\n", 169 | "\n", 170 | "import csv\n", 171 | "\n", 172 | "with open('example.csv',mode='w',newline='') as file:\n", 173 | " writer=csv.writer(file)\n", 174 | " writer.writerow(['name','age'])\n", 175 | " writer.writerow(['Krish',32])\n", 176 | "\n", 177 | "with open('example.csv',mode='r') as file:\n", 178 | " reader=csv.reader(file)\n", 179 | " for row in reader:\n", 180 | " print(row)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 12, 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "2024-06-11 11:37:28.084474\n", 193 | "2024-06-10 11:37:28.084474\n" 194 | ] 195 | } 196 | ], 197 | "source": [ 198 | "## datetime\n", 199 | "from datetime import datetime,timedelta\n", 200 | "\n", 201 | "now=datetime.now()\n", 202 | "print(now)\n", 203 | "\n", 204 | "yesterday=now-timedelta(days=1)\n", 205 | "\n", 206 | "print(yesterday)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 13, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "name": "stdout", 216 | "output_type": "stream", 217 | "text": [ 218 | "1718086104.8242216\n", 219 | "1718086106.82563\n" 220 | ] 221 | } 222 | ], 223 | "source": [ 224 | "## time\n", 225 | "import time\n", 226 | "print(time.time())\n", 227 | "time.sleep(2)\n", 228 | "print(time.time())" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 15, 234 | "metadata": {}, 235 | "outputs": [ 236 | { 237 | "name": "stdout", 238 | "output_type": "stream", 239 | "text": [ 240 | "123\n" 241 | ] 242 | } 243 | ], 244 | "source": [ 245 | "## Regular expresiion\n", 246 | "import re\n", 247 | "\n", 248 | "pattern=r'\\d+'\n", 249 | "text='There are 123 apples 456'\n", 250 | "match=re.search(pattern,text)\n", 251 | "print(match.group())" 252 | ] 253 | }, 254 | { 255 | "cell_type": "markdown", 256 | "metadata": {}, 257 | "source": [ 258 | "#### Conclusion\n", 259 | "Python's Standard Library is extensive and provides tools for almost any task you can think of, from file handling to web services, from data serialization to concurrent execution. Familiarizing yourself with the modules and packages available in the Standard Library can significantly enhance your ability to write efficient and effective Python programs." 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": null, 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [] 268 | } 269 | ], 270 | "metadata": { 271 | "kernelspec": { 272 | "display_name": "Python 3", 273 | "language": "python", 274 | "name": "python3" 275 | }, 276 | "language_info": { 277 | "codemirror_mode": { 278 | "name": "ipython", 279 | "version": 3 280 | }, 281 | "file_extension": ".py", 282 | "mimetype": "text/x-python", 283 | "name": "python", 284 | "nbconvert_exporter": "python", 285 | "pygments_lexer": "ipython3", 286 | "version": "3.12.0" 287 | } 288 | }, 289 | "nbformat": 4, 290 | "nbformat_minor": 2 291 | } 292 | -------------------------------------------------------------------------------- /5-Modules/destination.txt: -------------------------------------------------------------------------------- 1 | Hello How are you? 2 | I am fine 3 | Welcome to the course -------------------------------------------------------------------------------- /5-Modules/example.csv: -------------------------------------------------------------------------------- 1 | name,age 2 | Krish,32 3 | -------------------------------------------------------------------------------- /5-Modules/package/__init__.py: -------------------------------------------------------------------------------- 1 | '''__init__.py is a special file used in Python to define 2 | packages and initialize their namespaces 3 | ''' -------------------------------------------------------------------------------- /5-Modules/package/__pycache__/__init__.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/5-Modules/package/__pycache__/__init__.cpython-312.pyc -------------------------------------------------------------------------------- /5-Modules/package/__pycache__/maths.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/5-Modules/package/__pycache__/maths.cpython-312.pyc -------------------------------------------------------------------------------- /5-Modules/package/maths.py: -------------------------------------------------------------------------------- 1 | def addition(a,b): 2 | return a+b 3 | 4 | def substraction(a,b): 5 | return a-b 6 | 7 | -------------------------------------------------------------------------------- /5-Modules/package/subpackages/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/5-Modules/package/subpackages/__init__.py -------------------------------------------------------------------------------- /5-Modules/package/subpackages/__pycache__/__init__.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/5-Modules/package/subpackages/__pycache__/__init__.cpython-312.pyc -------------------------------------------------------------------------------- /5-Modules/package/subpackages/__pycache__/mult.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/5-Modules/package/subpackages/__pycache__/mult.cpython-312.pyc -------------------------------------------------------------------------------- /5-Modules/package/subpackages/mult.py: -------------------------------------------------------------------------------- 1 | def multiply(a,b): 2 | return a*b -------------------------------------------------------------------------------- /5-Modules/source.txt: -------------------------------------------------------------------------------- 1 | Hello How are you? 2 | I am fine 3 | Welcome to the course -------------------------------------------------------------------------------- /5-Modules/test.py: -------------------------------------------------------------------------------- 1 | from package.maths import * 2 | from package.subpackages.mult import multiply 3 | 4 | print(addition(2,3)) 5 | print(substraction(4,3)) 6 | print(multiply(4,5)) -------------------------------------------------------------------------------- /6-File Handling/6.1-fileoperation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### File Operation- Read And Write Files\n", 8 | "\n", 9 | "File handling is a crucial part of any programming language. Python provides built-in functions and methods to read from and write to files, both text and binary. This lesson will cover the basics of file handling, including reading and writing text files and binary files." 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 | "Hello How are you?\n", 22 | "I am good\n", 23 | "Krish is my name\n", 24 | "Welcome to the course\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "### Read a Whole File\n", 30 | "\n", 31 | "with open('example.txt','r') as file:\n", 32 | " content=file.read()\n", 33 | " print(content)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 6, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "Hello How are you?\n", 46 | "I am good\n", 47 | "Krish is my name\n", 48 | "Welcome to the course\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "## Read a file line by line\n", 54 | "with open('example.txt','r') as file:\n", 55 | " for line in file:\n", 56 | " print(line.strip()) ## sstrip() removes the newline character" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 7, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "## Writing a file(Overwriting)\n", 66 | "\n", 67 | "with open('example.txt','w') as file:\n", 68 | " file.write('Hello World!\\n')\n", 69 | " file.write('this is a new line.')" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 10, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "## Write a file(wwithout Overwriting)\n", 79 | "with open('example.txt','a') as file:\n", 80 | " file.write(\"Append operation taking place!\\n\")" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 11, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "### Writing a list of lines to a file\n", 90 | "lines=['First line \\n','Second line \\n','Third line\\n']\n", 91 | "with open('example.txt','a') as file:\n", 92 | " file.writelines(lines)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 12, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "### Binary Files\n", 102 | "\n", 103 | "# Writing to a binary file\n", 104 | "data = b'\\x00\\x01\\x02\\x03\\x04'\n", 105 | "with open('example.bin', 'wb') as file:\n", 106 | " file.write(data)\n" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 13, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "b'\\x00\\x01\\x02\\x03\\x04'\n" 119 | ] 120 | } 121 | ], 122 | "source": [ 123 | "# Reading a binary file\n", 124 | "with open('example.bin', 'rb') as file:\n", 125 | " content = file.read()\n", 126 | " print(content)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 14, 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "### Read the content froma source text fiile and write to a destination text file\n", 136 | "# Copying a text file\n", 137 | "with open('example.txt', 'r') as source_file:\n", 138 | " content = source_file.read()\n", 139 | "\n", 140 | "with open('destination.txt', 'w') as destination_file:\n", 141 | " destination_file.write(content)\n" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "#Read a text file and count the number of lines, words, and characters.\n", 151 | "# Counting lines, words, and characters in a text file\n", 152 | "def count_text_file(file_path):\n", 153 | " with open(file_path, 'r') as file:\n", 154 | " lines = file.readlines()\n", 155 | " line_count = len(lines)\n", 156 | " word_count = sum(len(line.split()) for line in lines)\n", 157 | " char_count = sum(len(line) for line in lines)\n", 158 | " return line_count, word_count, char_count\n", 159 | "\n", 160 | "file_path = 'example.txt'\n", 161 | "lines, words, characters = count_text_file(file_path)\n", 162 | "print(f'Lines: {lines}, Words: {words}, Characters: {characters}')\n" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "The w+ mode in Python is used to open a file for both reading and writing. If the file does not exist, it will be created. If the file exists, its content is truncated (i.e., the file is overwritten)." 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 17, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "Hello world\n", 182 | "This is a new line \n", 183 | "\n" 184 | ] 185 | } 186 | ], 187 | "source": [ 188 | "### Writing and then reading a file\n", 189 | "\n", 190 | "with open('example.txt','w+') as file:\n", 191 | " file.write(\"Hello world\\n\")\n", 192 | " file.write(\"This is a new line \\n\")\n", 193 | "\n", 194 | " ## Move the file cursor to the beginning\n", 195 | " file.seek(0)\n", 196 | "\n", 197 | " ## Read the content of the file\n", 198 | " content=file.read()\n", 199 | " print(content)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": null, 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [] 222 | } 223 | ], 224 | "metadata": { 225 | "kernelspec": { 226 | "display_name": "Python 3", 227 | "language": "python", 228 | "name": "python3" 229 | }, 230 | "language_info": { 231 | "codemirror_mode": { 232 | "name": "ipython", 233 | "version": 3 234 | }, 235 | "file_extension": ".py", 236 | "mimetype": "text/x-python", 237 | "name": "python", 238 | "nbconvert_exporter": "python", 239 | "pygments_lexer": "ipython3", 240 | "version": "3.12.0" 241 | } 242 | }, 243 | "nbformat": 4, 244 | "nbformat_minor": 2 245 | } 246 | -------------------------------------------------------------------------------- /6-File Handling/6.2-filepath.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Working With File Paths\n", 8 | "When working with files in Python, handling file paths correctly is crucial to ensure your code works across different operating systems and environments. Python provides several modules and functions for working with file paths effectively." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "name": "stdout", 18 | "output_type": "stream", 19 | "text": [ 20 | "Current working directory is e:\\UDemy Final\\python\\6-File Handling\n" 21 | ] 22 | } 23 | ], 24 | "source": [ 25 | "#### Using the os module\n", 26 | "import os\n", 27 | "cwd=os.getcwd()\n", 28 | "print(f\"Current working directory is {cwd}\")" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 5, 34 | "metadata": {}, 35 | "outputs": [ 36 | { 37 | "name": "stdout", 38 | "output_type": "stream", 39 | "text": [ 40 | "Directory 'package' create\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "## create a new directory\n", 46 | "new_directory=\"package\"\n", 47 | "os.mkdir(new_directory)\n", 48 | "print(f\"Directory '{new_directory}' create\")\n" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 6, 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "name": "stdout", 58 | "output_type": "stream", 59 | "text": [ 60 | "['6.1-fileoperation.ipynb', '6.2-filepath.ipynb', 'destination.txt', 'example.bin', 'example.txt', 'package']\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "## Listing Files And Directories\n", 66 | "items=os.listdir('.')\n", 67 | "print(items)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 7, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "name": "stdout", 77 | "output_type": "stream", 78 | "text": [ 79 | "folder\\file.txt\n" 80 | ] 81 | } 82 | ], 83 | "source": [ 84 | "### Joining Paths\n", 85 | "\n", 86 | "dir_name=\"folder\"\n", 87 | "file_name=\"file.txt\"\n", 88 | "full_path=os.path.join(dir_name,file_name)\n", 89 | "print(full_path)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 8, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "e:\\UDemy Final\\python\\6-File Handling\\folder\\file.txt\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "\n", 107 | "dir_name=\"folder\"\n", 108 | "file_name=\"file.txt\"\n", 109 | "full_path=os.path.join(os.getcwd(),dir_name,file_name)\n", 110 | "print(full_path)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 9, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "The path 'example1.txt' does not exists\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "path='example1.txt'\n", 128 | "if os.path.exists(path):\n", 129 | " print(f\"The path '{path}' exists\")\n", 130 | "else:\n", 131 | " print(f\"The path '{path}' does not exists\")" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 10, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "The path 'example.txt' is a file.\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "#Checking if a Path is a File or Directory\n", 149 | "import os\n", 150 | "\n", 151 | "path = 'example.txt'\n", 152 | "if os.path.isfile(path):\n", 153 | " print(f\"The path '{path}' is a file.\")\n", 154 | "elif os.path.isdir(path):\n", 155 | " print(f\"The path '{path}' is a directory.\")\n", 156 | "else:\n", 157 | " print(f\"The path '{path}' is neither a file nor a directory.\")\n" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 11, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "e:\\UDemy Final\\python\\6-File Handling\\example.txt\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "## Getting the absolute path\n", 175 | "relative_path='example.txt'\n", 176 | "absolute_path=os.path.abspath(relative_path)\n", 177 | "print(absolute_path)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": null, 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [] 186 | } 187 | ], 188 | "metadata": { 189 | "kernelspec": { 190 | "display_name": "Python 3", 191 | "language": "python", 192 | "name": "python3" 193 | }, 194 | "language_info": { 195 | "codemirror_mode": { 196 | "name": "ipython", 197 | "version": 3 198 | }, 199 | "file_extension": ".py", 200 | "mimetype": "text/x-python", 201 | "name": "python", 202 | "nbconvert_exporter": "python", 203 | "pygments_lexer": "ipython3", 204 | "version": "3.12.0" 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 2 209 | } 210 | -------------------------------------------------------------------------------- /6-File Handling/destination.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | this is a new line.Append operation taking place!Append operation taking place! 3 | Append operation taking place! 4 | First line 5 | Seocnd line 6 | Third line 7 | -------------------------------------------------------------------------------- /6-File Handling/example.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /6-File Handling/example.txt: -------------------------------------------------------------------------------- 1 | Hello world 2 | This is a new line 3 | -------------------------------------------------------------------------------- /7-Exception Handling/7.1-exception.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Understanding Exceptions\n", 8 | "\n", 9 | "Exception handling in Python allows you to handle errors gracefully and take corrective actions without stopping the execution of the program. This lesson will cover the basics of exceptions, including how to use try, except, else, and finally blocks." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "##### What Are Exceptions?\n", 17 | "Exceptions are events that disrupt the normal flow of a program. They occur when an error is encountered during program execution. Common exceptions include:\n", 18 | "\n", 19 | "- ZeroDivisionError: Dividing by zero.\n", 20 | "- FileNotFoundError: File not found.\n", 21 | "- ValueError: Invalid value.\n", 22 | "- TypeError: Invalid type." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 3, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "The variable has not been assigned\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "## Exception try ,except block\n", 40 | "\n", 41 | "try:\n", 42 | " a=b\n", 43 | "except:\n", 44 | " print(\"The variable has not been assigned\")" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 4, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "ename": "NameError", 54 | "evalue": "name 'b' is not defined", 55 | "output_type": "error", 56 | "traceback": [ 57 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 58 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 59 | "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m a\u001b[38;5;241m=\u001b[39m\u001b[43mb\u001b[49m\n", 60 | "\u001b[1;31mNameError\u001b[0m: name 'b' is not defined" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "a=b" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 5, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "name 'b' is not defined\n" 78 | ] 79 | } 80 | ], 81 | "source": [ 82 | "try:\n", 83 | " a=b\n", 84 | "except NameError as ex:\n", 85 | " print(ex)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 8, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "name": "stdout", 95 | "output_type": "stream", 96 | "text": [ 97 | "division by zero\n", 98 | "Please enter the denominator greater than 0\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "try:\n", 104 | " result=1/0\n", 105 | "except ZeroDivisionError as ex:\n", 106 | " print(ex)\n", 107 | " print(\"Please enter the denominator greater than 0\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 11, 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "name 'b' is not defined\n", 120 | "Main exception got caught here\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "try:\n", 126 | " result=1/2\n", 127 | " a=b\n", 128 | "except ZeroDivisionError as ex:\n", 129 | " print(ex)\n", 130 | " print(\"Please enter the denominator greater than 0\")\n", 131 | "except Exception as ex1:\n", 132 | " print(ex1)\n", 133 | " print('Main exception got caught here')" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 14, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "try:\n", 143 | " num=int(input(\"Enter a number\"))\n", 144 | " result=10/num\n", 145 | "except ValueError:\n", 146 | " print(\"This is not a valid number\")\n", 147 | "except ZeroDivisionError:\n", 148 | " print(\"enter denominator greater than 0\")\n", 149 | "except Exception as ex:\n", 150 | " print(ex)" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 16, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "You can't divide by zero!\n" 163 | ] 164 | } 165 | ], 166 | "source": [ 167 | "## try,except,else block\n", 168 | "try:\n", 169 | " num=int(input(\"Enter a number:\"))\n", 170 | " result=10/num\n", 171 | "except ValueError:\n", 172 | " print(\"That's not a valid number!\")\n", 173 | "except ZeroDivisionError:\n", 174 | " print(\"You can't divide by zero!\")\n", 175 | "except Exception as ex:\n", 176 | " print(ex)\n", 177 | "else:\n", 178 | " print(f\"the result is {result}\")\n", 179 | "\n", 180 | " \n", 181 | "\n" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 18, 187 | "metadata": {}, 188 | "outputs": [ 189 | { 190 | "name": "stdout", 191 | "output_type": "stream", 192 | "text": [ 193 | "You can't divide by zero!\n", 194 | "Execution complete.\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "## try,except,else and finally\n", 200 | "try:\n", 201 | " num = int(input(\"Enter a number: \"))\n", 202 | " result = 10 / num\n", 203 | "except ValueError:\n", 204 | " print(\"That's not a valid number!\")\n", 205 | "except ZeroDivisionError:\n", 206 | " print(\"You can't divide by zero!\")\n", 207 | "except Exception as ex:\n", 208 | " print(ex)\n", 209 | "else:\n", 210 | " print(f\"The result is {result}\")\n", 211 | "finally:\n", 212 | " print(\"Execution complete.\")\n", 213 | "\n" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 25, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "name 'b' is not defined\n", 226 | "file close\n" 227 | ] 228 | } 229 | ], 230 | "source": [ 231 | "### File handling and Exception HAndling\n", 232 | "\n", 233 | "try:\n", 234 | " file=open('example1.txt','r')\n", 235 | " content=file.read()\n", 236 | " a=b\n", 237 | " print(content)\n", 238 | "\n", 239 | "except FileNotFoundError:\n", 240 | " print(\"The file does not exists\")\n", 241 | "except Exception as ex:\n", 242 | " print(ex)\n", 243 | "\n", 244 | "finally:\n", 245 | " if 'file' in locals() or not file.closed():\n", 246 | " file.close()\n", 247 | " print('file close')" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": 22, 253 | "metadata": {}, 254 | "outputs": [ 255 | { 256 | "name": "stdout", 257 | "output_type": "stream", 258 | "text": [ 259 | "True\n" 260 | ] 261 | } 262 | ], 263 | "source": [ 264 | "if 'file' in locals():\n", 265 | " print(True)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 24, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "ename": "TypeError", 275 | "evalue": "'bool' object is not callable", 276 | "output_type": "error", 277 | "traceback": [ 278 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 279 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 280 | "Cell \u001b[1;32mIn[24], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[43mfile\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclosed\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", 281 | "\u001b[1;31mTypeError\u001b[0m: 'bool' object is not callable" 282 | ] 283 | } 284 | ], 285 | "source": [ 286 | "not file.closed()" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "metadata": {}, 293 | "outputs": [], 294 | "source": [] 295 | } 296 | ], 297 | "metadata": { 298 | "kernelspec": { 299 | "display_name": "Python 3", 300 | "language": "python", 301 | "name": "python3" 302 | }, 303 | "language_info": { 304 | "codemirror_mode": { 305 | "name": "ipython", 306 | "version": 3 307 | }, 308 | "file_extension": ".py", 309 | "mimetype": "text/x-python", 310 | "name": "python", 311 | "nbconvert_exporter": "python", 312 | "pygments_lexer": "ipython3", 313 | "version": "3.12.0" 314 | } 315 | }, 316 | "nbformat": 4, 317 | "nbformat_minor": 2 318 | } 319 | -------------------------------------------------------------------------------- /7-Exception Handling/example1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdzaheerjk/Complete-Python-Bootcamp/ea077f9d330ff9c758f19ff2c324845a577afa9f/7-Exception Handling/example1.txt -------------------------------------------------------------------------------- /8-Class And Objects/8.1-oops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Classes and Objects\n", 8 | "Object-Oriented Programming (OOP) is a programming paradigm that uses \"objects\" to design applications and computer programs. OOP allows for modeling real-world scenarios using classes and objects. This lesson covers the basics of creating classes and objects, including instance variables and methods." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "name": "stdout", 18 | "output_type": "stream", 19 | "text": [ 20 | "\n" 21 | ] 22 | } 23 | ], 24 | "source": [ 25 | "### A class is a blue print for creating objects. Attributes,methods\n", 26 | "class Car:\n", 27 | " pass\n", 28 | "\n", 29 | "audi=Car()\n", 30 | "bmw=Car()\n", 31 | "\n", 32 | "print(type(audi))\n" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "<__main__.Car object at 0x0000015A0B79FF20>\n", 45 | "<__main__.Car object at 0x0000015A0A3374A0>\n" 46 | ] 47 | } 48 | ], 49 | "source": [ 50 | "print(audi)\n", 51 | "print(bmw)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 4, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "4\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "audi.windows=4\n", 69 | "\n", 70 | "print(audi.windows)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 5, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "ename": "AttributeError", 80 | "evalue": "'Car' object has no attribute 'windows'", 81 | "output_type": "error", 82 | "traceback": [ 83 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 84 | "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", 85 | "Cell \u001b[1;32mIn[5], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m tata\u001b[38;5;241m=\u001b[39mCar()\n\u001b[0;32m 2\u001b[0m tata\u001b[38;5;241m.\u001b[39mdoors\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m4\u001b[39m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mtata\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwindows\u001b[49m)\n", 86 | "\u001b[1;31mAttributeError\u001b[0m: 'Car' object has no attribute 'windows'" 87 | ] 88 | } 89 | ], 90 | "source": [ 91 | "tata=Car()\n", 92 | "tata.doors=4\n", 93 | "print(tata.windows)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 6, 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "data": { 103 | "text/plain": [ 104 | "['__class__',\n", 105 | " '__delattr__',\n", 106 | " '__dict__',\n", 107 | " '__dir__',\n", 108 | " '__doc__',\n", 109 | " '__eq__',\n", 110 | " '__format__',\n", 111 | " '__ge__',\n", 112 | " '__getattribute__',\n", 113 | " '__getstate__',\n", 114 | " '__gt__',\n", 115 | " '__hash__',\n", 116 | " '__init__',\n", 117 | " '__init_subclass__',\n", 118 | " '__le__',\n", 119 | " '__lt__',\n", 120 | " '__module__',\n", 121 | " '__ne__',\n", 122 | " '__new__',\n", 123 | " '__reduce__',\n", 124 | " '__reduce_ex__',\n", 125 | " '__repr__',\n", 126 | " '__setattr__',\n", 127 | " '__sizeof__',\n", 128 | " '__str__',\n", 129 | " '__subclasshook__',\n", 130 | " '__weakref__',\n", 131 | " 'doors']" 132 | ] 133 | }, 134 | "execution_count": 6, 135 | "metadata": {}, 136 | "output_type": "execute_result" 137 | } 138 | ], 139 | "source": [ 140 | "dir(tata)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 9, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "<__main__.Dog object at 0x0000015A0B7E99D0>\n", 153 | "Buddy\n", 154 | "3\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "### Instance Variable and Methods\n", 160 | "class Dog:\n", 161 | " ## constructor\n", 162 | " def __init__(self,name,age):\n", 163 | " self.name=name\n", 164 | " self.age=age\n", 165 | "\n", 166 | "## create objects\n", 167 | "dog1=Dog(\"Buddy\",3)\n", 168 | "print(dog1)\n", 169 | "print(dog1.name)\n", 170 | "print(dog1.age)\n", 171 | " \n", 172 | " " 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 10, 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "Lucy\n", 185 | "4\n" 186 | ] 187 | } 188 | ], 189 | "source": [ 190 | "dog2=Dog(\"Lucy\",4)\n", 191 | "print(dog2.name)\n", 192 | "print(dog2.age)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 12, 198 | "metadata": {}, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "Buddy says woof\n", 205 | "Lucy says woof\n" 206 | ] 207 | } 208 | ], 209 | "source": [ 210 | "## Define a class with instance methods\n", 211 | "class Dog:\n", 212 | " def __init__(self,name,age):\n", 213 | " self.name=name\n", 214 | " self.age=age\n", 215 | " \n", 216 | " def bark(self):\n", 217 | " print(f\"{self.name} says woof\")\n", 218 | "\n", 219 | "\n", 220 | "dog1=Dog(\"Buddy\",3)\n", 221 | "dog1.bark()\n", 222 | "dog2=Dog(\"Lucy\",4)\n", 223 | "dog2.bark()\n", 224 | "\n" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 13, 230 | "metadata": {}, 231 | "outputs": [ 232 | { 233 | "name": "stdout", 234 | "output_type": "stream", 235 | "text": [ 236 | "5000\n" 237 | ] 238 | } 239 | ], 240 | "source": [ 241 | "### Modeling a Bank Account\n", 242 | "\n", 243 | "## Define a class for bank account\n", 244 | "class BankAccount:\n", 245 | " def __init__(self,owner,balance=0):\n", 246 | " self.owner=owner\n", 247 | " self.balance=balance\n", 248 | "\n", 249 | " def deposit(self,amount):\n", 250 | " self.balance+=amount\n", 251 | " print(f\"{amount} is deposited. New balance is {self.balance}\")\n", 252 | "\n", 253 | " def withdraw(self,amount):\n", 254 | " if amount>self.balance:\n", 255 | " print(\"Insufficient funds!\")\n", 256 | " else:\n", 257 | " self.balance-=amount\n", 258 | " print(f\"{amount} is withdrawn. New Balance is {self.balance}\")\n", 259 | "\n", 260 | " def get_balance(self):\n", 261 | " return self.balance\n", 262 | " \n", 263 | "## create an account\n", 264 | "\n", 265 | "account=BankAccount(\"Krish\",5000)\n", 266 | "print(account.balance)\n", 267 | "\n", 268 | " " 269 | ] 270 | }, 271 | { 272 | "cell_type": "markdown", 273 | "metadata": {}, 274 | "source": [] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": 14, 279 | "metadata": {}, 280 | "outputs": [ 281 | { 282 | "name": "stdout", 283 | "output_type": "stream", 284 | "text": [ 285 | "100 is deposited. New balance is 5100\n" 286 | ] 287 | } 288 | ], 289 | "source": [ 290 | "## Call isntance methods\n", 291 | "account.deposit(100)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 15, 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "name": "stdout", 301 | "output_type": "stream", 302 | "text": [ 303 | "300 is withdrawn. New Balance is 4800\n" 304 | ] 305 | } 306 | ], 307 | "source": [ 308 | "account.withdraw(300)" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 16, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "name": "stdout", 318 | "output_type": "stream", 319 | "text": [ 320 | "4800\n" 321 | ] 322 | } 323 | ], 324 | "source": [ 325 | "print(account.get_balance())" 326 | ] 327 | }, 328 | { 329 | "cell_type": "markdown", 330 | "metadata": {}, 331 | "source": [ 332 | "#### Conclusion\n", 333 | "Object-Oriented Programming (OOP) allows you to model real-world scenarios using classes and objects. In this lesson, you learned how to create classes and objects, define instance variables and methods, and use them to perform various operations. Understanding these concepts is fundamental to writing effective and maintainable Python code." 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": null, 339 | "metadata": {}, 340 | "outputs": [], 341 | "source": [] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": null, 346 | "metadata": {}, 347 | "outputs": [], 348 | "source": [] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": null, 353 | "metadata": {}, 354 | "outputs": [], 355 | "source": [] 356 | } 357 | ], 358 | "metadata": { 359 | "kernelspec": { 360 | "display_name": "Python 3", 361 | "language": "python", 362 | "name": "python3" 363 | }, 364 | "language_info": { 365 | "codemirror_mode": { 366 | "name": "ipython", 367 | "version": 3 368 | }, 369 | "file_extension": ".py", 370 | "mimetype": "text/x-python", 371 | "name": "python", 372 | "nbconvert_exporter": "python", 373 | "pygments_lexer": "ipython3", 374 | "version": "3.12.0" 375 | } 376 | }, 377 | "nbformat": 4, 378 | "nbformat_minor": 2 379 | } 380 | -------------------------------------------------------------------------------- /8-Class And Objects/8.2-inheritance.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Inheritance In Python\n", 8 | "Inheritance is a fundamental concept in Object-Oriented Programming (OOP) that allows a class to inherit attributes and methods from another class. This lesson covers single inheritance and multiple inheritance, demonstrating how to create and use them in Python." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "## Inheritance (Single Inheritance)\n", 18 | "## Parent class\n", 19 | "class Car:\n", 20 | " def __init__(self,windows,doors,enginetype):\n", 21 | " self.windows=windows\n", 22 | " self.doors=doors\n", 23 | " self.enginetype=enginetype\n", 24 | " \n", 25 | " def drive(self):\n", 26 | " print(f\"The person will drive the {self.enginetype} car \")\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 3, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "The person will drive the petrol car \n" 39 | ] 40 | } 41 | ], 42 | "source": [ 43 | "car1=Car(4,5,\"petrol\")\n", 44 | "car1.drive()" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 4, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "class Tesla(Car):\n", 54 | " def __init__(self,windows,doors,enginetype,is_selfdriving):\n", 55 | " super().__init__(windows,doors,enginetype)\n", 56 | " self.is_selfdriving=is_selfdriving\n", 57 | "\n", 58 | " def selfdriving(self):\n", 59 | " print(f\"Tesla supports self driving : {self.is_selfdriving}\")" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 6, 65 | "metadata": {}, 66 | "outputs": [ 67 | { 68 | "name": "stdout", 69 | "output_type": "stream", 70 | "text": [ 71 | "Tesla supports self driving : True\n" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "tesla1=Tesla(4,5,\"electric\",True)\n", 77 | "tesla1.selfdriving()" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 7, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "The person will drive the electric car \n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "tesla1.drive()" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 9, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "Buddy say woof\n", 107 | "Owner:Krish\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "### Multiple Inheritance\n", 113 | "## When a class inherits from more than one base class.\n", 114 | "## Base class 1\n", 115 | "class Animal:\n", 116 | " def __init__(self,name):\n", 117 | " self.name=name\n", 118 | "\n", 119 | " def speak(self):\n", 120 | " print(\"Subclass must implement this method\")\n", 121 | "\n", 122 | "## BAse class 2\n", 123 | "class Pet:\n", 124 | " def __init__(self, owner):\n", 125 | " self.owner = owner\n", 126 | "\n", 127 | "\n", 128 | "##Derived class\n", 129 | "class Dog(Animal,Pet):\n", 130 | " def __init__(self,name,owner):\n", 131 | " Animal.__init__(self,name)\n", 132 | " Pet.__init__(self,owner)\n", 133 | "\n", 134 | " def speak(self):\n", 135 | " return f\"{self.name} say woof\"\n", 136 | " \n", 137 | "\n", 138 | "## Create an object\n", 139 | "dog=Dog(\"Buddy\",\"Krish\")\n", 140 | "print(dog.speak())\n", 141 | "print(f\"Owner:{dog.owner}\")\n", 142 | "\n", 143 | "\n" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "#### Conclusion\n", 151 | "Inheritance is a powerful feature in OOP that allows for code reuse and the creation of a more logical class structure. Single inheritance involves one base class, while multiple inheritance involves more than one base class. Understanding how to implement and use inheritance in Python will enable you to design more efficient and maintainable object-oriented programs." 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [] 181 | } 182 | ], 183 | "metadata": { 184 | "kernelspec": { 185 | "display_name": "Python 3", 186 | "language": "python", 187 | "name": "python3" 188 | }, 189 | "language_info": { 190 | "codemirror_mode": { 191 | "name": "ipython", 192 | "version": 3 193 | }, 194 | "file_extension": ".py", 195 | "mimetype": "text/x-python", 196 | "name": "python", 197 | "nbconvert_exporter": "python", 198 | "pygments_lexer": "ipython3", 199 | "version": "3.12.0" 200 | } 201 | }, 202 | "nbformat": 4, 203 | "nbformat_minor": 2 204 | } 205 | -------------------------------------------------------------------------------- /8-Class And Objects/8.3-Polymorphism.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Polymorphism\n", 8 | "Polymorphism is a core concept in Object-Oriented Programming (OOP) that allows objects of different classes to be treated as objects of a common superclass. It provides a way to perform a single action in different forms. Polymorphism is typically achieved through method overriding and interfaces" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "### Method Overriding\n", 16 | "Method overriding allows a child class to provide a specific implementation of a method that is already defined in its parent class." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 3, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "Woof!\n", 29 | "Meow!\n", 30 | "Woof!\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "## Base Class\n", 36 | "class Animal:\n", 37 | " def speak(self):\n", 38 | " return \"Sound of the animal\"\n", 39 | " \n", 40 | "## Derived Class 1\n", 41 | "class Dog(Animal):\n", 42 | " def speak(self):\n", 43 | " return \"Woof!\"\n", 44 | " \n", 45 | "## Derived class\n", 46 | "class Cat(Animal):\n", 47 | " def speak(self):\n", 48 | " return \"Meow!\"\n", 49 | " \n", 50 | "## Function that demonstrates polymorphism\n", 51 | "def animal_speak(animal):\n", 52 | " print(animal.speak())\n", 53 | " \n", 54 | "dog=Dog()\n", 55 | "cat=Cat()\n", 56 | "print(dog.speak())\n", 57 | "print(cat.speak())\n", 58 | "animal_speak(dog)\n" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 5, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "the area is 20\n", 71 | "the area is 28.259999999999998\n" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "### Polymorphissm with Functions and MEthods\n", 77 | "## base class\n", 78 | "class Shape:\n", 79 | " def area(self):\n", 80 | " return \"The area of the figure\"\n", 81 | " \n", 82 | "## Derived class 1\n", 83 | "class Rectangle(Shape):\n", 84 | " def __init__(self,width,height):\n", 85 | " self.width=width\n", 86 | " self.height=height\n", 87 | "\n", 88 | " def area(self):\n", 89 | " return self.width * self.height\n", 90 | " \n", 91 | "##DErived class 2\n", 92 | "\n", 93 | "class Circle(Shape):\n", 94 | " def __init__(self,radius):\n", 95 | " self.radius=radius\n", 96 | "\n", 97 | " def area(self):\n", 98 | " return 3.14*self.radius *self.radius\n", 99 | " \n", 100 | "## Fucntion that demonstrates polymorphism\n", 101 | "\n", 102 | "def print_area(shape):\n", 103 | " print(f\"the area is {shape.area()}\")\n", 104 | "\n", 105 | "\n", 106 | "rectangle=Rectangle(4,5)\n", 107 | "circle=Circle(3)\n", 108 | "\n", 109 | "print_area(rectangle)\n", 110 | "print_area(circle)\n", 111 | "\n", 112 | "\n", 113 | "\n" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "#### Polymorphism with Abstract Base Classes\n", 121 | "Abstract Base Classes (ABCs) are used to define common methods for a group of related objects. They can enforce that derived classes implement particular methods, promoting consistency across different implementations." 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 6, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "Car enginer started\n" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "from abc import ABC,abstractmethod\n", 139 | "\n", 140 | "## Define an abstract class\n", 141 | "class Vehicle(ABC):\n", 142 | " @abstractmethod\n", 143 | " def start_engine(self):\n", 144 | " pass\n", 145 | "\n", 146 | "## Derived class 1\n", 147 | "class Car(Vehicle):\n", 148 | " def start_engine(self):\n", 149 | " return \"Car enginer started\"\n", 150 | " \n", 151 | "## Derived class 2\n", 152 | "class Motorcycle(Vehicle):\n", 153 | " def start_engine(self):\n", 154 | " return \"Motorcycle enginer started\"\n", 155 | " \n", 156 | "# Function that demonstrates polymorphism\n", 157 | "def start_vehicle(vehicle):\n", 158 | " print(vehicle.start_engine())\n", 159 | "\n", 160 | "## create objects of cAr and Motorcycle\n", 161 | "\n", 162 | "car = Car()\n", 163 | "motorcycle = Motorcycle()\n", 164 | "\n", 165 | "start_vehicle(car)\n", 166 | "\n", 167 | "\n" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": {}, 173 | "source": [ 174 | "#### Conclusion\n", 175 | "Polymorphism is a powerful feature of OOP that allows for flexibility and integration in code design. It enables a single function to handle objects of different classes, each with its own implementation of a method. By understanding and applying polymorphism, you can create more extensible and maintainable object-oriented programs." 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": null, 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": null, 188 | "metadata": {}, 189 | "outputs": [], 190 | "source": [] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "metadata": {}, 224 | "outputs": [], 225 | "source": [] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": null, 230 | "metadata": {}, 231 | "outputs": [], 232 | "source": [] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": null, 237 | "metadata": {}, 238 | "outputs": [], 239 | "source": [] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": null, 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [] 254 | } 255 | ], 256 | "metadata": { 257 | "kernelspec": { 258 | "display_name": "Python 3", 259 | "language": "python", 260 | "name": "python3" 261 | }, 262 | "language_info": { 263 | "codemirror_mode": { 264 | "name": "ipython", 265 | "version": 3 266 | }, 267 | "file_extension": ".py", 268 | "mimetype": "text/x-python", 269 | "name": "python", 270 | "nbconvert_exporter": "python", 271 | "pygments_lexer": "ipython3", 272 | "version": "3.12.0" 273 | } 274 | }, 275 | "nbformat": 4, 276 | "nbformat_minor": 2 277 | } 278 | -------------------------------------------------------------------------------- /8-Class And Objects/8.4-Encapsulation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Encapsulation And Abstraction\n", 8 | "Encapsulation and abstraction are two fundamental principles of Object-Oriented Programming (OOP) that help in designing robust, maintainable, and reusable code. Encapsulation involves bundling data and methods that operate on the data within a single unit, while abstraction involves hiding complex implementation details and exposing only the necessary features." 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "##### Encapsulation\n", 16 | "Encapsulation is the concept of wrapping data (variables) and methods (functions) together as a single unit. It restricts direct access to some of the object's components, which is a means of preventing accidental interference and misuse of the data.\n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 5, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "data": { 26 | "text/plain": [ 27 | "'Krish'" 28 | ] 29 | }, 30 | "execution_count": 5, 31 | "metadata": {}, 32 | "output_type": "execute_result" 33 | } 34 | ], 35 | "source": [ 36 | "### Encapsulation with Getter and Setter MEthods\n", 37 | "### Public,protected,private variables or access modifiers\n", 38 | "\n", 39 | "class Person:\n", 40 | " def __init__(self,name,age):\n", 41 | " self.name=name ## public variables\n", 42 | " self.age=age ## public variables\n", 43 | "\n", 44 | "def get_name(person):\n", 45 | " return person.name\n", 46 | "\n", 47 | "person=Person(\"Krish\",34)\n", 48 | "get_name(person)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "data": { 58 | "text/plain": [ 59 | "['__class__',\n", 60 | " '__delattr__',\n", 61 | " '__dict__',\n", 62 | " '__dir__',\n", 63 | " '__doc__',\n", 64 | " '__eq__',\n", 65 | " '__format__',\n", 66 | " '__ge__',\n", 67 | " '__getattribute__',\n", 68 | " '__getstate__',\n", 69 | " '__gt__',\n", 70 | " '__hash__',\n", 71 | " '__init__',\n", 72 | " '__init_subclass__',\n", 73 | " '__le__',\n", 74 | " '__lt__',\n", 75 | " '__module__',\n", 76 | " '__ne__',\n", 77 | " '__new__',\n", 78 | " '__reduce__',\n", 79 | " '__reduce_ex__',\n", 80 | " '__repr__',\n", 81 | " '__setattr__',\n", 82 | " '__sizeof__',\n", 83 | " '__str__',\n", 84 | " '__subclasshook__',\n", 85 | " '__weakref__',\n", 86 | " 'age',\n", 87 | " 'name']" 88 | ] 89 | }, 90 | "execution_count": 3, 91 | "metadata": {}, 92 | "output_type": "execute_result" 93 | } 94 | ], 95 | "source": [ 96 | "dir(person)" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 15, 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "ename": "AttributeError", 106 | "evalue": "'Person' object has no attribute '__name'", 107 | "output_type": "error", 108 | "traceback": [ 109 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 110 | "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", 111 | "Cell \u001b[1;32mIn[15], line 11\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m person\u001b[38;5;241m.\u001b[39m__name\n\u001b[0;32m 10\u001b[0m person\u001b[38;5;241m=\u001b[39mPerson(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mKrish\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;241m34\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMale\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 11\u001b[0m \u001b[43mget_name\u001b[49m\u001b[43m(\u001b[49m\u001b[43mperson\u001b[49m\u001b[43m)\u001b[49m\n", 112 | "Cell \u001b[1;32mIn[15], line 8\u001b[0m, in \u001b[0;36mget_name\u001b[1;34m(person)\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_name\u001b[39m(person):\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mperson\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__name\u001b[49m\n", 113 | "\u001b[1;31mAttributeError\u001b[0m: 'Person' object has no attribute '__name'" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "class Person:\n", 119 | " def __init__(self,name,age,gender):\n", 120 | " self.__name=name ## private variables\n", 121 | " self.__age=age ## private variables\n", 122 | " self.gender=gender\n", 123 | "\n", 124 | "def get_name(person):\n", 125 | " return person.__name\n", 126 | "\n", 127 | "person=Person(\"Krish\",34,\"Male\")\n", 128 | "get_name(person)\n" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 12, 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/plain": [ 139 | "['_Person__age',\n", 140 | " '_Person__name',\n", 141 | " '__class__',\n", 142 | " '__delattr__',\n", 143 | " '__dict__',\n", 144 | " '__dir__',\n", 145 | " '__doc__',\n", 146 | " '__eq__',\n", 147 | " '__format__',\n", 148 | " '__ge__',\n", 149 | " '__getattribute__',\n", 150 | " '__getstate__',\n", 151 | " '__gt__',\n", 152 | " '__hash__',\n", 153 | " '__init__',\n", 154 | " '__init_subclass__',\n", 155 | " '__le__',\n", 156 | " '__lt__',\n", 157 | " '__module__',\n", 158 | " '__ne__',\n", 159 | " '__new__',\n", 160 | " '__reduce__',\n", 161 | " '__reduce_ex__',\n", 162 | " '__repr__',\n", 163 | " '__setattr__',\n", 164 | " '__sizeof__',\n", 165 | " '__str__',\n", 166 | " '__subclasshook__',\n", 167 | " '__weakref__',\n", 168 | " 'gender']" 169 | ] 170 | }, 171 | "execution_count": 12, 172 | "metadata": {}, 173 | "output_type": "execute_result" 174 | } 175 | ], 176 | "source": [ 177 | "dir(person)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 20, 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "name": "stdout", 187 | "output_type": "stream", 188 | "text": [ 189 | "KRish\n" 190 | ] 191 | } 192 | ], 193 | "source": [ 194 | "class Person:\n", 195 | " def __init__(self,name,age,gender):\n", 196 | " self._name=name ## protected variables\n", 197 | " self._age=age ## protected variables\n", 198 | " self.gender=gender\n", 199 | "\n", 200 | "class Employee(Person):\n", 201 | " def __init__(self,name,age,gender):\n", 202 | " super().__init__(name,age,gender)\n", 203 | "\n", 204 | "\n", 205 | "employee=Employee(\"KRish\",34,\"Male\")\n", 206 | "print(employee._name)\n" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 21, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "name": "stdout", 216 | "output_type": "stream", 217 | "text": [ 218 | "Krish\n", 219 | "34\n", 220 | "35\n", 221 | "Age cannot be negative.\n" 222 | ] 223 | } 224 | ], 225 | "source": [ 226 | "## Encapsulation With Getter And Setter\n", 227 | "class Person:\n", 228 | " def __init__(self,name,age):\n", 229 | " self.__name=name ## Private access modifier or variable\n", 230 | " self.__age=age ## Private variable\n", 231 | "\n", 232 | " ## getter method for name\n", 233 | " def get_name(self):\n", 234 | " return self.__name\n", 235 | " \n", 236 | " ## setter method for name\n", 237 | " def set_name(self,name):\n", 238 | " self.__name=name\n", 239 | "\n", 240 | " # Getter method for age\n", 241 | " def get_age(self):\n", 242 | " return self.__age\n", 243 | " \n", 244 | " # Setter method for age\n", 245 | " def set_age(self, age):\n", 246 | " if age > 0:\n", 247 | " self.__age = age\n", 248 | " else:\n", 249 | " print(\"Age cannot be negative.\")\n", 250 | "\n", 251 | "\n", 252 | "person=Person(\"Krish\",34)\n", 253 | "\n", 254 | "## Access and modify private variables using getter and setter\n", 255 | "\n", 256 | "print(person.get_name())\n", 257 | "print(person.get_age())\n", 258 | "\n", 259 | "person.set_age(35)\n", 260 | "print(person.get_age())\n", 261 | "\n", 262 | "person.set_age(-5)\n", 263 | " \n" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": null, 269 | "metadata": {}, 270 | "outputs": [], 271 | "source": [] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "metadata": {}, 277 | "outputs": [], 278 | "source": [] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": null, 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": null, 290 | "metadata": {}, 291 | "outputs": [], 292 | "source": [] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": null, 297 | "metadata": {}, 298 | "outputs": [], 299 | "source": [] 300 | } 301 | ], 302 | "metadata": { 303 | "kernelspec": { 304 | "display_name": "Python 3", 305 | "language": "python", 306 | "name": "python3" 307 | }, 308 | "language_info": { 309 | "codemirror_mode": { 310 | "name": "ipython", 311 | "version": 3 312 | }, 313 | "file_extension": ".py", 314 | "mimetype": "text/x-python", 315 | "name": "python", 316 | "nbconvert_exporter": "python", 317 | "pygments_lexer": "ipython3", 318 | "version": "3.12.0" 319 | } 320 | }, 321 | "nbformat": 4, 322 | "nbformat_minor": 2 323 | } 324 | -------------------------------------------------------------------------------- /8-Class And Objects/8.5-Abstraction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Abstraction\n", 8 | "Abstraction is the concept of hiding the complex implementation details and showing only the necessary features of an object. This helps in reducing programming complexity and effort." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 3, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "name": "stdout", 18 | "output_type": "stream", 19 | "text": [ 20 | "Car enginer started\n", 21 | "The vehicle is used for driving\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "from abc import ABC,abstractmethod\n", 27 | "\n", 28 | "## Abstract base cclass\n", 29 | "class Vehicle(ABC):\n", 30 | " def drive(self):\n", 31 | " print(\"The vehicle is used for driving\")\n", 32 | "\n", 33 | " @abstractmethod\n", 34 | " def start_engine(self):\n", 35 | " pass\n", 36 | "\n", 37 | "class Car(Vehicle):\n", 38 | " def start_engine(self):\n", 39 | " print(\"Car enginer started\")\n", 40 | "\n", 41 | "def operate_vehicle(vehicle):\n", 42 | " vehicle.start_engine()\n", 43 | " vehicle.drive()\n", 44 | "\n", 45 | "car=Car()\n", 46 | "operate_vehicle(car)\n", 47 | "\n" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [] 84 | } 85 | ], 86 | "metadata": { 87 | "kernelspec": { 88 | "display_name": "Python 3", 89 | "language": "python", 90 | "name": "python3" 91 | }, 92 | "language_info": { 93 | "codemirror_mode": { 94 | "name": "ipython", 95 | "version": 3 96 | }, 97 | "file_extension": ".py", 98 | "mimetype": "text/x-python", 99 | "name": "python", 100 | "nbconvert_exporter": "python", 101 | "pygments_lexer": "ipython3", 102 | "version": "3.12.0" 103 | } 104 | }, 105 | "nbformat": 4, 106 | "nbformat_minor": 2 107 | } 108 | -------------------------------------------------------------------------------- /8-Class And Objects/8.6-magicmethods.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Magic Methods\n", 8 | "Magic methods in Python, also known as dunder methods (double underscore methods), are special methods that start and end with double underscores. These methods enable you to define the behavior of objects for built-in operations, such as arithmetic operations, comparisons, and more." 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "##### Magic Methods\n", 16 | "Magic methods are predefined methods in Python that you can override to change the behavior of your objects. Some common magic methods include:\n", 17 | "\n" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "data": { 27 | "text/plain": [ 28 | "\"\\n__init__': Initializes a new instance of a class.\\n__str__: Returns a string representation of an object.\\n__repr__: Returns an official string representation of an object.\\n__len__: Returns the length of an object.\\n__getitem__: Gets an item from a container.\\n__setitem__: Sets an item in a container.\\n\"" 29 | ] 30 | }, 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "output_type": "execute_result" 34 | } 35 | ], 36 | "source": [ 37 | "'''\n", 38 | "__init__': Initializes a new instance of a class.\n", 39 | "__str__: Returns a string representation of an object.\n", 40 | "__repr__: Returns an official string representation of an object.\n", 41 | "__len__: Returns the length of an object.\n", 42 | "__getitem__: Gets an item from a container.\n", 43 | "__setitem__: Sets an item in a container.\n", 44 | "'''" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 2, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "data": { 54 | "text/plain": [ 55 | "['__class__',\n", 56 | " '__delattr__',\n", 57 | " '__dict__',\n", 58 | " '__dir__',\n", 59 | " '__doc__',\n", 60 | " '__eq__',\n", 61 | " '__format__',\n", 62 | " '__ge__',\n", 63 | " '__getattribute__',\n", 64 | " '__getstate__',\n", 65 | " '__gt__',\n", 66 | " '__hash__',\n", 67 | " '__init__',\n", 68 | " '__init_subclass__',\n", 69 | " '__le__',\n", 70 | " '__lt__',\n", 71 | " '__module__',\n", 72 | " '__ne__',\n", 73 | " '__new__',\n", 74 | " '__reduce__',\n", 75 | " '__reduce_ex__',\n", 76 | " '__repr__',\n", 77 | " '__setattr__',\n", 78 | " '__sizeof__',\n", 79 | " '__str__',\n", 80 | " '__subclasshook__',\n", 81 | " '__weakref__']" 82 | ] 83 | }, 84 | "execution_count": 2, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "class Person:\n", 91 | " pass\n", 92 | "\n", 93 | "person=Person()\n", 94 | "dir(person)" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 3, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "<__main__.Person object at 0x0000029E5D059940>\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "print(person)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 4, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "<__main__.Person object at 0x0000029E5D31D4C0>\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "## Basics MEthods\n", 129 | "class Person:\n", 130 | " def __init__(self,name,age):\n", 131 | " self.name=name\n", 132 | " self.age=age\n", 133 | "person=Person(\"KRish\",34)\n", 134 | "print(person)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 6, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "KRish,34 years old\n", 147 | "Person(name=KRish,age=34)\n" 148 | ] 149 | } 150 | ], 151 | "source": [ 152 | "## Basics MEthods\n", 153 | "class Person:\n", 154 | " def __init__(self,name,age):\n", 155 | " self.name=name\n", 156 | " self.age=age\n", 157 | " \n", 158 | " def __str__(self):\n", 159 | " return f\"{self.name},{self.age} years old\"\n", 160 | " \n", 161 | " def __repr__(self):\n", 162 | " return f\"Person(name={self.name},age={self.age})\"\n", 163 | " \n", 164 | "person=Person(\"KRish\",34)\n", 165 | "print(person)\n", 166 | "print(repr(person))" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [] 175 | } 176 | ], 177 | "metadata": { 178 | "kernelspec": { 179 | "display_name": "Python 3", 180 | "language": "python", 181 | "name": "python3" 182 | }, 183 | "language_info": { 184 | "codemirror_mode": { 185 | "name": "ipython", 186 | "version": 3 187 | }, 188 | "file_extension": ".py", 189 | "mimetype": "text/x-python", 190 | "name": "python", 191 | "nbconvert_exporter": "python", 192 | "pygments_lexer": "ipython3", 193 | "version": "3.12.0" 194 | } 195 | }, 196 | "nbformat": 4, 197 | "nbformat_minor": 2 198 | } 199 | -------------------------------------------------------------------------------- /8-Class And Objects/8.7-OperatorOverloading.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "##### Operator Overloading\n", 8 | "Operator overloading allows you to define the behavior of operators (+, -, *, etc.) for custom objects. You achieve this by overriding specific magic methods in your class." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 2, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "data": { 18 | "text/plain": [ 19 | "'\\n__add__(self, other): Adds two objects using the + operator.\\n__sub__(self, other): Subtracts two objects using the - operator.\\n__mul__(self, other): Multiplies two objects using the * operator.\\n__truediv__(self, other): Divides two objects using the / operator.\\n__eq__(self, other): Checks if two objects are equal using the == operator.\\n__lt__(self, other): Checks if one object is less than another using the < operator.\\n\\n'" 20 | ] 21 | }, 22 | "execution_count": 2, 23 | "metadata": {}, 24 | "output_type": "execute_result" 25 | } 26 | ], 27 | "source": [ 28 | "#### Common Operator Overloading Magic Methods\n", 29 | "'''\n", 30 | "__add__(self, other): Adds two objects using the + operator.\n", 31 | "__sub__(self, other): Subtracts two objects using the - operator.\n", 32 | "__mul__(self, other): Multiplies two objects using the * operator.\n", 33 | "__truediv__(self, other): Divides two objects using the / operator.\n", 34 | "__eq__(self, other): Checks if two objects are equal using the == operator.\n", 35 | "__lt__(self, other): Checks if one object is less than another using the < operator.\n", 36 | "\n", 37 | "__gt__\n", 38 | "'''" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 6, 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "name": "stdout", 48 | "output_type": "stream", 49 | "text": [ 50 | "Vector(6, 8)\n", 51 | "Vector(-2, -2)\n", 52 | "Vector(6, 9)\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "### MAthematical operation for vectors\n", 58 | "class Vector:\n", 59 | " def __init__(self,x,y):\n", 60 | " self.x=x\n", 61 | " self.y=y\n", 62 | "\n", 63 | " def __add__(self,other):\n", 64 | " return Vector(self.x+other.x,self.y+other.y)\n", 65 | " \n", 66 | " def __sub__(self, other):\n", 67 | " return Vector(self.x - other.x, self.y - other.y)\n", 68 | "\n", 69 | " def __mul__(self, other):\n", 70 | " return Vector(self.x * other, self.y * other)\n", 71 | " \n", 72 | " def __eq__(self, other):\n", 73 | " return self.x == other.x and self.y == other.y\n", 74 | " \n", 75 | " def __repr__(self):\n", 76 | " return f\"Vector({self.x}, {self.y})\"\n", 77 | " \n", 78 | "## create objectss of the Vector Class\n", 79 | "v1=Vector(2,3)\n", 80 | "v2=Vector(4,5)\n", 81 | "\n", 82 | "print(v1+v2)\n", 83 | "print(v1-v2)\n", 84 | "print(v1*3)\n" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "### Overloading Operators for Complex Numbers\n", 94 | "\n", 95 | "class ComplexNumber:\n", 96 | " def __init__(self, real, imag):\n", 97 | " self.real = real\n", 98 | " self.imag = imag\n", 99 | "\n", 100 | " def __add__(self, other):\n", 101 | " return ComplexNumber(self.real + other.real, self.imag + other.imag)\n", 102 | "\n", 103 | " def __sub__(self, other):\n", 104 | " return ComplexNumber(self.real - other.real, self.imag - other.imag)\n", 105 | "\n", 106 | " def __mul__(self, other):\n", 107 | " real_part = self.real * other.real - self.imag * other.imag\n", 108 | " imag_part = self.real * other.imag + self.imag * other.real\n", 109 | " return ComplexNumber(real_part, imag_part)\n", 110 | "\n", 111 | " def __truediv__(self, other):\n", 112 | " denominator = other.real**2 + other.imag**2\n", 113 | " real_part = (self.real * other.real + self.imag * other.imag) / denominator\n", 114 | " imag_part = (self.imag * other.real - self.real * other.imag) / denominator\n", 115 | " return ComplexNumber(real_part, imag_part)\n", 116 | "\n", 117 | " def __eq__(self, other):\n", 118 | " return self.real == other.real and self.imag == other.imag\n", 119 | "\n", 120 | " def __repr__(self):\n", 121 | " return f\"{self.real} + {self.imag}i\"\n", 122 | "\n", 123 | "# Create objects of the ComplexNumber class\n", 124 | "c1 = ComplexNumber(2, 3)\n", 125 | "c2 = ComplexNumber(1, 4)\n", 126 | "\n", 127 | "# Use overloaded operators\n", 128 | "print(c1 + c2) # Output: 3 + 7i\n", 129 | "print(c1 - c2) # Output: 1 - 1i\n", 130 | "print(c1 * c2) # Output: -10 + 11i\n", 131 | "print(c1 / c2) # Output: 0.8235294117647058 - 0.29411764705882354i\n", 132 | "print(c1 == c2) # Output: False\n" 133 | ] 134 | } 135 | ], 136 | "metadata": { 137 | "kernelspec": { 138 | "display_name": "Python 3", 139 | "language": "python", 140 | "name": "python3" 141 | }, 142 | "language_info": { 143 | "codemirror_mode": { 144 | "name": "ipython", 145 | "version": 3 146 | }, 147 | "file_extension": ".py", 148 | "mimetype": "text/x-python", 149 | "name": "python", 150 | "nbconvert_exporter": "python", 151 | "pygments_lexer": "ipython3", 152 | "version": "3.12.0" 153 | } 154 | }, 155 | "nbformat": 4, 156 | "nbformat_minor": 2 157 | } 158 | -------------------------------------------------------------------------------- /9-Advance Python Concepts/9.1-Iterators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Iterators\n", 8 | "Iterators are advanced Python concepts that allow for efficient looping and memory management. Iterators provide a way to access elements of a collection sequentially without exposing the underlying structure.\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 6, 14 | "metadata": {}, 15 | "outputs": [ 16 | { 17 | "name": "stdout", 18 | "output_type": "stream", 19 | "text": [ 20 | "1\n", 21 | "2\n", 22 | "3\n", 23 | "4\n", 24 | "5\n", 25 | "6\n" 26 | ] 27 | } 28 | ], 29 | "source": [ 30 | "my_list=[1,2,3,4,5,6]\n", 31 | "for i in my_list:\n", 32 | " print(i)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 7, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "text/plain": [ 43 | "list" 44 | ] 45 | }, 46 | "execution_count": 7, 47 | "metadata": {}, 48 | "output_type": "execute_result" 49 | } 50 | ], 51 | "source": [ 52 | "type(my_list)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 8, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "[1, 2, 3, 4, 5, 6]\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "print(my_list)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 9, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "## Iterator\n", 87 | "iterator=iter(my_list)\n", 88 | "print(type(iterator))" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 10, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "text/plain": [ 99 | "" 100 | ] 101 | }, 102 | "execution_count": 10, 103 | "metadata": {}, 104 | "output_type": "execute_result" 105 | } 106 | ], 107 | "source": [ 108 | "iterator" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 17, 114 | "metadata": {}, 115 | "outputs": [ 116 | { 117 | "ename": "StopIteration", 118 | "evalue": "", 119 | "output_type": "error", 120 | "traceback": [ 121 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 122 | "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", 123 | "Cell \u001b[1;32mIn[17], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m## Iterate through all the element\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43miterator\u001b[49m\u001b[43m)\u001b[49m\n", 124 | "\u001b[1;31mStopIteration\u001b[0m: " 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "## Iterate through all the element\n", 130 | "\n", 131 | "next(iterator)" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 18, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "iterator=iter(my_list)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 25, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "There are no elements in the iterator\n" 153 | ] 154 | } 155 | ], 156 | "source": [ 157 | "\n", 158 | "\n", 159 | "try:\n", 160 | " print(next(iterator))\n", 161 | "except StopIteration:\n", 162 | " print(\"There are no elements in the iterator\")" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 26, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "name": "stdout", 172 | "output_type": "stream", 173 | "text": [ 174 | "H\n", 175 | "e\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "# String iterator\n", 181 | "my_string = \"Hello\"\n", 182 | "string_iterator = iter(my_string)\n", 183 | "\n", 184 | "print(next(string_iterator)) # Output: H\n", 185 | "print(next(string_iterator)) # Output: e" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": null, 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [] 222 | } 223 | ], 224 | "metadata": { 225 | "kernelspec": { 226 | "display_name": "Python 3", 227 | "language": "python", 228 | "name": "python3" 229 | }, 230 | "language_info": { 231 | "codemirror_mode": { 232 | "name": "ipython", 233 | "version": 3 234 | }, 235 | "file_extension": ".py", 236 | "mimetype": "text/x-python", 237 | "name": "python", 238 | "nbconvert_exporter": "python", 239 | "pygments_lexer": "ipython3", 240 | "version": "3.12.0" 241 | } 242 | }, 243 | "nbformat": 4, 244 | "nbformat_minor": 2 245 | } 246 | -------------------------------------------------------------------------------- /9-Advance Python Concepts/9.2-Generators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Generators\n", 8 | "Generators are a simpler way to create iterators. They use the yield keyword to produce a series of values lazily, which means they generate values on the fly and do not store them in memory." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 3, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "def square(n):\n", 18 | " for i in range(3):\n", 19 | " yield i**2" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 4, 25 | "metadata": {}, 26 | "outputs": [ 27 | { 28 | "data": { 29 | "text/plain": [ 30 | "" 31 | ] 32 | }, 33 | "execution_count": 4, 34 | "metadata": {}, 35 | "output_type": "execute_result" 36 | } 37 | ], 38 | "source": [ 39 | "square(3)" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 5, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "0\n", 52 | "1\n", 53 | "4\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "for i in square(3):\n", 59 | " print(i)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 6, 65 | "metadata": {}, 66 | "outputs": [ 67 | { 68 | "data": { 69 | "text/plain": [ 70 | "" 71 | ] 72 | }, 73 | "execution_count": 6, 74 | "metadata": {}, 75 | "output_type": "execute_result" 76 | } 77 | ], 78 | "source": [ 79 | "a=square(3)\n", 80 | "a" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 10, 86 | "metadata": {}, 87 | "outputs": [ 88 | { 89 | "ename": "StopIteration", 90 | "evalue": "", 91 | "output_type": "error", 92 | "traceback": [ 93 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 94 | "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", 95 | "Cell \u001b[1;32mIn[10], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m)\u001b[49m\n", 96 | "\u001b[1;31mStopIteration\u001b[0m: " 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "next(a)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 11, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "def my_generator():\n", 111 | " yield 1\n", 112 | " yield 2\n", 113 | " yield 3" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 17, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "" 125 | ] 126 | }, 127 | "execution_count": 17, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "gen=my_generator()\n", 134 | "gen" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 16, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "ename": "StopIteration", 144 | "evalue": "", 145 | "output_type": "error", 146 | "traceback": [ 147 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 148 | "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", 149 | "Cell \u001b[1;32mIn[16], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mgen\u001b[49m\u001b[43m)\u001b[49m\n", 150 | "\u001b[1;31mStopIteration\u001b[0m: " 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "next(gen)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 18, 161 | "metadata": {}, 162 | "outputs": [ 163 | { 164 | "name": "stdout", 165 | "output_type": "stream", 166 | "text": [ 167 | "1\n", 168 | "2\n", 169 | "3\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "for val in gen:\n", 175 | " print(val)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "#### Practical Example: Reading Large Files\n", 183 | "Generators are particularly useful for reading large files because they allow you to process one line at a time without loading the entire file into memory." 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 19, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "### Practical : Reading LArge Files\n", 193 | "\n", 194 | "def read_large_file(file_path):\n", 195 | " with open(file_path,'r') as file:\n", 196 | " for line in file:\n", 197 | " yield line" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 20, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | "Smt. Droupadi Murmu was sworn in as the 15th President of India on 25 July, 2022. Previously, she was the Governor of Jharkhand from 2015 to 2021. She has devoted her life to empowering the downtrodden and the marginalised sections and deepening the democratic values.\n", 210 | "\n", 211 | "Early Life and Education\n", 212 | "\n", 213 | "Born in a Santhali tribal family on 20 June, 1958 at Uparbeda village, Mayurbhanj, Odisha, Smt. Murmu’s early life was marked by hardships and struggle. On completion of primary education from the village school, she went to Bhubaneswar on her own initiative to continue her studies. She earned the degree of Bachelor of Arts from Ramadevi Women’s College, Bhubaneswar and became the first woman from her village to receive college education.\n", 214 | "\n", 215 | "Professional Career\n", 216 | "\n", 217 | "From 1979 to 1983, Smt. Murmu served as a Junior Assistant in the Irrigation and Power Department, Government of Odisha. Later, she served as an honorary teacher at Sri Aurobindo Integral Education Centre, Rairangpur, from 1994 to 1997.\n", 218 | "\n", 219 | "Public Life\n", 220 | "\n", 221 | "In 2000, Smt. Murmu was elected from the Rairangpur constituency as a Member of the Legislative Assembly of Odisha and continued to hold the post till 2009, serving two terms. During this period, she served as Minister of State (Independent Charge), Department of Commerce and Transport in the Government of Odisha from March 6, 2000 to August 6, 2002 and as Minister of State (Independent Charge), Department of Fisheries and Animal Resources Development, Government of Odisha from Augu\n" 222 | ] 223 | } 224 | ], 225 | "source": [ 226 | "file_path='large_file.txt'\n", 227 | "\n", 228 | "for line in read_large_file(file_path):\n", 229 | " print(line.strip())" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "#### Conclusion\n", 237 | "Iterators and generators are powerful tools in Python for creating and handling sequences of data efficiently. Iterators provide a way to access elements sequentially, while generators allow you to generate items on the fly, making them particularly useful for handling large datasets and infinite sequences. Understanding these concepts will enable you to write more efficient and memory-conscious Python programs." 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "metadata": {}, 244 | "outputs": [], 245 | "source": [] 246 | } 247 | ], 248 | "metadata": { 249 | "kernelspec": { 250 | "display_name": "Python 3", 251 | "language": "python", 252 | "name": "python3" 253 | }, 254 | "language_info": { 255 | "codemirror_mode": { 256 | "name": "ipython", 257 | "version": 3 258 | }, 259 | "file_extension": ".py", 260 | "mimetype": "text/x-python", 261 | "name": "python", 262 | "nbconvert_exporter": "python", 263 | "pygments_lexer": "ipython3", 264 | "version": "3.12.0" 265 | } 266 | }, 267 | "nbformat": 4, 268 | "nbformat_minor": 2 269 | } 270 | -------------------------------------------------------------------------------- /9-Advance Python Concepts/large_file.txt: -------------------------------------------------------------------------------- 1 | Smt. Droupadi Murmu was sworn in as the 15th President of India on 25 July, 2022. Previously, she was the Governor of Jharkhand from 2015 to 2021. She has devoted her life to empowering the downtrodden and the marginalised sections and deepening the democratic values. 2 | 3 | Early Life and Education 4 | 5 | Born in a Santhali tribal family on 20 June, 1958 at Uparbeda village, Mayurbhanj, Odisha, Smt. Murmu’s early life was marked by hardships and struggle. On completion of primary education from the village school, she went to Bhubaneswar on her own initiative to continue her studies. She earned the degree of Bachelor of Arts from Ramadevi Women’s College, Bhubaneswar and became the first woman from her village to receive college education. 6 | 7 | Professional Career 8 | 9 | From 1979 to 1983, Smt. Murmu served as a Junior Assistant in the Irrigation and Power Department, Government of Odisha. Later, she served as an honorary teacher at Sri Aurobindo Integral Education Centre, Rairangpur, from 1994 to 1997. 10 | 11 | Public Life 12 | 13 | In 2000, Smt. Murmu was elected from the Rairangpur constituency as a Member of the Legislative Assembly of Odisha and continued to hold the post till 2009, serving two terms. During this period, she served as Minister of State (Independent Charge), Department of Commerce and Transport in the Government of Odisha from March 6, 2000 to August 6, 2002 and as Minister of State (Independent Charge), Department of Fisheries and Animal Resources Development, Government of Odisha from Augu -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Complete-Python-Bootcamp 2 | --- 3 | 4 | # 🚀 Complete Python Bootcamp 🐍 5 | 6 | Welcome to the **Complete Python Bootcamp**! Whether you're a beginner looking to start your Python journey or someone aiming to level up your skills, this bootcamp has you covered. From Python basics to advanced concepts, dive in and explore a variety of projects and learning modules that will make you a Python pro! 💻✨ 7 | 8 | --- 9 | 10 | ## 📚 What’s Inside? 11 | 12 | This repository covers a comprehensive list of topics, starting from Python basics to more advanced concepts. Here’s an overview of what you’ll find: 13 | 14 | ### 1️⃣ **Python Basics** 15 | - Learn the foundation of Python programming with variables, data types, and basic syntax. 🧩 16 | 17 | ### 2️⃣ **Control Flow** 18 | - Master conditionals (if-else) and loops (for, while) to make your programs smarter! 🔄 19 | 20 | ### 3️⃣ **Data Structures** 21 | - Dive into lists, dictionaries, sets, and tuples, learning how to manipulate and store data efficiently. 🗃️ 22 | 23 | ### 4️⃣ **Functions** 24 | - Get comfortable with defining and using functions to make your code modular and reusable. 🔧 25 | 26 | ### 5️⃣ **Modules** 27 | - Understand how to import and use modules to extend the functionality of your programs. 📦 28 | 29 | ### 6️⃣ **File Handling** 30 | - Learn how to work with files (reading, writing, and modifying them) in Python. 📝 31 | 32 | ### 7️⃣ **Exception Handling** 33 | - Handle errors and exceptions gracefully to make your code robust and reliable. 🚨 34 | 35 | ### 8️⃣ **Classes and Objects** 36 | - Dive into Object-Oriented Programming (OOP) and understand the concept of classes and objects. 🏷️ 37 | 38 | ### 9️⃣ **Advanced Python Concepts** 39 | - Explore more advanced topics like decorators, generators, and context managers. 🌟 40 | 41 | ### 🔟 **Data Analysis with Python** 42 | - Learn how to use Python libraries like Pandas and NumPy for data manipulation and analysis. 📊 43 | 44 | ### 1️⃣1️⃣ **Working with Databases** 45 | - Master the art of interacting with databases using Python and SQL. 🗃️ 46 | 47 | ### 1️⃣2️⃣ **Logging in Python** 48 | - Learn to log your Python applications for better debugging and maintenance. 📜 49 | 50 | ### 1️⃣3️⃣ **Flask** 51 | - Understand how to create web applications with Flask, a micro-framework for Python. 🌍 52 | 53 | ### 1️⃣4️⃣ **Streamlit** 54 | - Build interactive data applications with Streamlit and visualize data in a user-friendly way. 📈 55 | 56 | ### 1️⃣5️⃣ **Memory Management** 57 | - Get insights into how Python manages memory and how you can optimize your programs. 💡 58 | 59 | ### 1️⃣6️⃣ **Multithreading & Multiprocessing** 60 | - Learn how to execute multiple tasks concurrently for performance improvement. ⚙️ 61 | 62 | --- 63 | 64 | ## 🛠️ Technologies Used: 65 | - **Python 3.x** 🐍 66 | - **Jupyter Notebooks** 📓 67 | - **Flask** 🌐 68 | - **Streamlit** 📊 69 | - **SQLite** 🗄️ 70 | 71 | --- 72 | 73 | ## 🚀 How to Get Started: 74 | 1. Clone the repository to your local machine: 75 | ```bash 76 | git clone https://github.com/mdzaheerjk/Complete-Python-Bootcamp.git 77 | ``` 78 | 2. Navigate into the project directory: 79 | ```bash 80 | cd Complete-Python-Bootcamp 81 | ``` 82 | 3. Install the required packages: 83 | ```bash 84 | pip install -r requirements.txt 85 | ``` 86 | 4. Open Jupyter notebooks or run any of the Python files to get started with the lessons! 87 | 88 | --- 89 | 90 | ## 📝 License: 91 | This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details. 92 | 93 | --- 94 | 95 | ## 🤝 Contributing: 96 | We welcome contributions! If you have any ideas or improvements, feel free to fork the repo, make changes, and create a pull request! 🚀 97 | 98 | --- 99 | 100 | ## 💬 Let's connect: 101 | - Follow me on GitHub for updates! 🔔 102 | - If you have any questions or need help, don't hesitate to open an issue! 🎯 103 | 104 | --- 105 | 106 | ## 🎉 Let's Code and Learn Python Together! 💡💻 107 | 108 | --- 109 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ipykernel 2 | numpy 3 | pandas 4 | matplotlib 5 | seaborn 6 | flask 7 | memory_profiler 8 | streamlit 9 | scikit-learn 10 | --------------------------------------------------------------------------------