├── .gitattributes ├── .gitignore ├── ABC.txt ├── ABCD.txt ├── Afunc.py ├── Basics ├── 01. Getting familiar with python.py ├── 02. Variables and Data Types.py ├── 03. Operators.py ├── 04. Strings.py ├── 05. If- elif- else.py ├── 06. Match Case.py ├── 07. For loop.py ├── 08. While Loops.py ├── 09. Break and Continue.py └── 10. Functions.py ├── Data Structures ├── 11. List.py ├── 12. Tuple.py ├── 13. Set.py └── 14. Dictionary.py ├── Error Handling ├── 15. Exception Handling.py └── 16. Customized Errors.py ├── LICENSE ├── Module and File Handling ├── 17. Import.py ├── 18. File Operations.py └── 19. Map.py ├── Object Oriented Programming ├── 20. OOP.py ├── 21. Constructor.py ├── 22. Decorators.py ├── 23. Getters and Setters.py ├── 24. Inheritance.py ├── 25. Access Specifiers or Access Modifiers.py ├── 26. Static Method.py ├── 27. Class Method.py ├── 28.Magic- Dunder Method.py ├── 29. Overriding.py ├── 30. Single Inheritance.py ├── 31. Multiple Inheritance.py ├── 32. Multilevel Inheritance.py ├── 33. Hybrid Inheritance.py └── 34. Hierarchical Inheritance.py ├── README.md └── Time Module └── 35. Time Module.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /ABC.txt: -------------------------------------------------------------------------------- 1 | This is a text file. 2 | This happens to be the place which i am going to use for the file operation in python. 3 | 4 | -------------------------------------------------------------------------------- /ABCD.txt: -------------------------------------------------------------------------------- 1 | one 2 | two 3 | three 4 | -------------------------------------------------------------------------------- /Afunc.py: -------------------------------------------------------------------------------- 1 | def Multiplication(a, b, c): 2 | print("a= ", a, "b= ", b, "c= ", c) 3 | print("Product is ", a*b*c) 4 | 5 | if __name__=="__main__": 6 | Multiplication(2,3,4) 7 | 8 | print("This is:- ",__name__) -------------------------------------------------------------------------------- /Basics/01. Getting familiar with python.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script demonstrates various input and output operations in Python, including type-specific inputs, 3 | multiple outputs, comments, and escape sequence usage. 4 | """ 5 | 6 | def main() -> None: 7 | """ 8 | Main function to execute the input-output demonstration. 9 | """ 10 | # Input section 11 | a: str = input("Enter the value: ") # Prompt user for a string input 12 | b: int = int(input("Enter an integer value: ")) # Prompt user for an integer input 13 | c: float = float(input("Enter a float value: ")) # Prompt user for a float input 14 | 15 | # Output section 16 | print(a) # Print the string input 17 | print(b + c) # Print the sum of integer and float inputs 18 | print(5 + 2) # Print a simple arithmetic result 19 | print("Python") # Print a string 20 | print(7, 8.12, "Python", sep="-", end="$\n") # Print with custom separator and end character 21 | 22 | # Multiple outputs in a single print statement 23 | print(a, 7, 8, 6 + 5,"S") # Print mixed values in one line 24 | 25 | # Escape Sequence Character Demonstration 26 | print("This is for escape sequence\t \" We can use\" symbol too\n Escape Sequence") 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /Basics/02. Variables and Data Types.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script demonstrates various input and output operations in Python, including type-specific inputs, 3 | multiple outputs, comments, variables, data types, and escape sequence usage. 4 | """ 5 | 6 | def main() -> None: 7 | """ 8 | Main function to execute the input-output demonstration. 9 | """ 10 | # Variables are like containers that hold data. 11 | # Variables can be updated, meaning they are dynamic, not static. 12 | a1: int = 1 13 | B1: int = 2 14 | _c1: int = 3 15 | # Note: Variable names cannot start with numbers, e.g., 1c_ = 4 would cause an error. 16 | 17 | print(a1, B1, _c1) # Print the values of variables 18 | print("This is type of a1", type(a1)) # Print the type of variable `a1` 19 | 20 | # Data type specifies the type of value a variable holds. 21 | ''' 22 | 5 types of data types: 23 | 1. Numeric: int, float, complex 24 | 2. String 25 | 3. Boolean: True, False 26 | 4. Sequenced: list- [], tuple- () -> list is mutable (can be modified) and tuple is immutable (cannot be modified) 27 | 5. Mapped: dictionary 28 | ''' 29 | print("Numeric Data Type= ", 3, " ", 7.83, " ", 6+2j) # Demonstrating int, float, and complex types 30 | print("String Data Type= ", "This is Python String", 'And we are learning Programming') # String example 31 | print("Boolean Data Type= ", True) # Boolean example 32 | print("Sequenced Data Type= ", [12, 15, 16, 18], " ", (11, 14, 17, 19)) # List and tuple examples 33 | print("Dictionary= ", {"name": "Rohan", "age": 25, "Student": True, "Stream": "MBA"}) # Dictionary example 34 | 35 | # Explicit typecasting - Done by user 36 | string: str = "15" 37 | number: int = 7 38 | string_number: int = int(string) # Throws an error if the string is not a valid integer 39 | sum_result: int = number + string_number 40 | print("The Sum of both the numbers is: ", sum_result) # Print the sum of explicitly casted values 41 | 42 | # Implicit typecasting - Done by Python automatically 43 | a: int = 7 # Python treats `a` as an integer 44 | print(type(a)) # Print type of `a` 45 | 46 | b: float = 3.0 # Python treats `b` as a float 47 | print(type(b)) # Print type of `b` 48 | 49 | c: float = a + b # Python automatically converts `a` to float during addition 50 | print(c) # Print the result of implicit typecasting 51 | print(type(c)) # Print type of `c` 52 | 53 | # Global and Local Variables 54 | # Variables defined inside a function body have a local scope, and those defined outside have a global scope. 55 | 56 | a: int = 1 # Global variable 57 | 58 | def x1() -> None: 59 | print('Inside x1(): ', a) # Accessing global variable `a` 60 | 61 | def x2() -> None: 62 | a: int = 2 # Local variable 63 | print('Inside x2(): ', a) # Here `a` = 2 using the local `a` 64 | 65 | def x3() -> None: 66 | global a 67 | a = 3 # Modifying the global variable 68 | print('Inside x3(): ', a) # Here `a` = 3 using global `a` because of the `global` keyword 69 | 70 | print('global: ', a) # Print initial value of global variable `a` 71 | x1() 72 | print('global: ', a) # Global `a` remains unchanged 73 | x2() 74 | print('global: ', a) # Global `a` remains unchanged 75 | x3() 76 | print('global: ', a) # Value of global `a` changes due to `x3` 77 | 78 | if __name__ == "__main__": 79 | main() 80 | -------------------------------------------------------------------------------- /Basics/03. Operators.py: -------------------------------------------------------------------------------- 1 | # Operators:- signs or keywords used to perform specific operation on multiple values or variables. 2 | # Types of Operators:- 3 | # Arithmetic Operators- +, -, *, /, **, //, % 4 | # Comparison Operators- <, >, <=. >=, ==, != 5 | # Assignment Operators- =, +=, -=, *=, %= 6 | # Logical Operators- AND, OR, NOT 7 | # Bitwise Operators- &, |, <<, >>, -, ^ 8 | 9 | # Arithmetic Operators 10 | a=3 11 | b=4 12 | c=6 13 | print(a+b, " ", a-b, " ", a*b, " ", c/b, " ", b**a, " ", c//b, " ", c%b) 14 | 15 | x= "Lord " 16 | y= "Voldemort " 17 | 18 | # Concatenation of Strings 19 | z= x+y 20 | print(z) 21 | 22 | # Replication of String 23 | print(z*a) 24 | 25 | # Comparison Operators 26 | 27 | print(a>b, " ", a=b, " ", a<=b) 28 | 29 | # 'is' vs '==' 30 | 31 | a, b= 3, 3 # Constant Immutable 32 | x, y = [1, 2, 3], [1, 2, 3] 33 | print( a==b, " ", a is b) 34 | print( x==y, " ", x is y) 35 | 36 | # Assignment Operators 37 | 38 | d= 16 39 | print(d) 40 | a+= 3 41 | print( a) 42 | b-= 2 43 | print( b) 44 | c*= 2 45 | print( c) 46 | c%= 5 47 | print( c) 48 | a/=2 49 | print( a) 50 | 51 | # Logical Operators 52 | 53 | if( a>1 and b==2): 54 | print(" And is working") 55 | 56 | if( a>1 or b<2): 57 | print(" If is working") 58 | 59 | if (not( a<1 and b>2)): 60 | print(" Not is working") 61 | 62 | # Bitwise Operators 63 | 64 | x = 5 # Binary: 0101 65 | y = 3 # Binary: 0011 66 | result = x & y # Binary: 0001 67 | print(result) 68 | x = 5 # Binary: 0101 69 | y = 3 # Binary: 0011 70 | result = x | y # Binary: 0111 71 | print(result) 72 | x = 5 # Binary: 0101 73 | y = 3 # Binary: 0011 74 | result = x ^ y # Binary: 0110 75 | print(result) 76 | x = 5 # Binary: 0101 77 | result = ~x # 2's complement 78 | print(result) 79 | x = 5 # Binary: 0101 80 | result = x << 2 81 | print(result) 82 | x = 5 # Binary: 0101 83 | result = x >> 2 # Binary: 0001 84 | print(result) -------------------------------------------------------------------------------- /Basics/04. Strings.py: -------------------------------------------------------------------------------- 1 | # Anything that is between single or double quotation marks is string. 2 | # It is basically a collection of Characters. Strings are Immutable. 3 | 4 | name = "Batman" # Batman is string 5 | print("Hello "+name) # Hellow is string 6 | b= "mohan's life is pretty lavish!!!" 7 | d="PETROL136" 8 | e=" Ranger " 9 | print(b) 10 | 11 | # Multi-line String 12 | 13 | a= """ 14 | An Apple a day keeps the doctor away 15 | But what if i am the doctor and 16 | i eat an Apple everyday, 17 | Will i be seperated from myself? 18 | Sounds interesting! 19 | """ 20 | print(a) 21 | 22 | # length of String 23 | 24 | x= len(a) 25 | print('length of a is:- ',x) 26 | 27 | # Accessing Specific Characters of String 28 | 29 | print(name[3]) 30 | 31 | # Slicing 32 | print(a[22:25]) 33 | print(a[:5]) 34 | print(a[-8:]) 35 | print(a[-14:148]) 36 | print(a.upper()) 37 | print(a.lower()) 38 | print(a.replace("Apple", "doctor")) 39 | print(a.split(" ")) 40 | print(a.count("Apple")) 41 | print(a.find("i")) 42 | print(a.index("i")) # Raises error when the value is not found 43 | print(a.swapcase()) 44 | print(a.isprintable()) 45 | print(a.isspace()) 46 | print(a.istitle()) 47 | print(a.title()) 48 | 49 | print(b.rstrip("!")) 50 | print(b.capitalize()) 51 | print(b.center(50,".")) 52 | print(b.endswith(".")) 53 | print(b.islower()) 54 | print(b.istitle()) 55 | print(b.title()) 56 | print(b.startswith("mohan's")) 57 | 58 | print(d.isalnum()) 59 | print(d.isupper()) 60 | 61 | print(e.strip()) 62 | 63 | print(name.swapcase()) 64 | print(name.isalpha()) 65 | 66 | # String Formatting or f-string 67 | b= "Shyam" 68 | c= "Wait for some time" 69 | a= "Welcome {} to this place we would like you to {}, right {}." 70 | x= "Welcome {0} to this place we would like you to {1}, right {1}." 71 | y= f"Welcome {b} to this place we would like you to {c}, right {c}." 72 | print(a.format(b,c,b)) 73 | print(x.format(b,c,b)) 74 | print(y) 75 | Weight=68.888 76 | print(f"Weight is {Weight:.1f}") 77 | print(f"The format of {{a}} will be give in the right way {2*4}") -------------------------------------------------------------------------------- /Basics/05. If- elif- else.py: -------------------------------------------------------------------------------- 1 | ''' 2 | An if-else loop is a conditional statement in programming that allows you to execute different code blocks based on 3 | whether a specified condition is true or false. It's a fundamental control flow structure that enables your program to 4 | make decisions and perform actions accordingly. 5 | ''' 6 | 7 | # If Loop 8 | 9 | a= input("Enter name:- ") 10 | b= "power" 11 | if(type(a)== type(b)): 12 | print("String ") 13 | 14 | # If- else Loop 15 | 16 | a= int(input("Enter your age:- ")) 17 | if(a>18): 18 | print("You can Vote") 19 | else: 20 | print("You cannot Vote") 21 | 22 | # If- elif Loop 23 | 24 | Selling_Price = int(input("Enter Selling Price of Your Product:- ")) 25 | Cost_Price = int(input("Enter Cost Price of Your Product:- ")) 26 | if (Selling_Price< Cost_Price): 27 | print("Profit ") 28 | elif(Selling_Price== Cost_Price): 29 | print("Nothing Gained") 30 | else: 31 | print("Loss") 32 | 33 | # Nested If Loop 34 | 35 | number = int(input("Enter any number:- ")) 36 | if (number < 0): 37 | print("Negative Number") 38 | elif (number > 0): 39 | print("Positive Number") 40 | if (number <= 10): 41 | print("Number in range 1-10") 42 | elif (number > 10 and number <= 20): 43 | print("Number in range 11-20") 44 | else: 45 | print("Number is greater than 20") 46 | else: 47 | print("Number is zero") 48 | 49 | # Ternary If- Else 50 | x=10 51 | y=50 52 | print(x) if xy else print(0) 53 | -------------------------------------------------------------------------------- /Basics/06. Match Case.py: -------------------------------------------------------------------------------- 1 | ''' 2 | General Syntax for Match- Case 3 | match value: 4 | case pattern1: 5 | # Code to execute if value matches pattern1 6 | case pattern2: 7 | # Code to execute if value matches pattern2 8 | case _: 9 | # Code to execute if value doesn't match any previous patterns 10 | 11 | ''' 12 | x = int(input("Enter Number: ")) 13 | # x is the variable to match 14 | match x: 15 | # if x is 0 16 | case 0: 17 | print("x is zero") 18 | # case with if-condition 19 | case 8 if x % 2 == 0: 20 | print("x % 2 == 0 and case is 8") 21 | # Empty case with if-condition 22 | case _ if x < 10: 23 | print("x is < 10") 24 | case _ if x!=90: 25 | print(x, "is not 90") 26 | case _ if x%3!=0: 27 | print(x, "is not 80") 28 | case _: # It is basically an else. 29 | print(x) 30 | -------------------------------------------------------------------------------- /Basics/07. For loop.py: -------------------------------------------------------------------------------- 1 | name = 'Saurabh' 2 | for i in name: 3 | print(i, end=", ") 4 | 5 | Directions= ["North ", "South", "East ", "West"] 6 | for i in Directions: 7 | print("Direction", i, end= ",") 8 | 9 | for x in range(5): 10 | print(x) 11 | 12 | for k in range(2,8): 13 | print(k) 14 | 15 | for i in range(5): 16 | print("Cool") 17 | else: 18 | print("Warm") 19 | 20 | # Enumerate 21 | 22 | a=[10,22,3,45,56,27.11] 23 | for a,b in enumerate(a, start= -1): 24 | print(b) 25 | if(a==3): 26 | print("Enumerated Successfully") 27 | -------------------------------------------------------------------------------- /Basics/08. While Loops.py: -------------------------------------------------------------------------------- 1 | # While Loops 2 | 3 | number= 5 4 | while (number > 0): 5 | print(number) 6 | number= number - 1 7 | 8 | # Else with While Loop 9 | 10 | x =10 11 | while (x > 2): 12 | print(x) 13 | x = x - 1 14 | else: 15 | print('counter is 0') 16 | 17 | # Do- While loop 18 | 19 | while True: 20 | number = int(input("Enter a positive number: ")) 21 | print(number) 22 | if not number > 0: 23 | break -------------------------------------------------------------------------------- /Basics/09. Break and Continue.py: -------------------------------------------------------------------------------- 1 | # Break 2 | 3 | for i in range(1,10,1): 4 | print(i ,end=" ") 5 | if(i==5): 6 | break 7 | else: 8 | print("Keep Moving") 9 | print("Understood Break ") 10 | 11 | i = 0 12 | while True: 13 | print(i) 14 | i = i + 1 15 | if(i%10 == 0): 16 | break 17 | 18 | # Continue 19 | 20 | for i in [2,3,4,6,8,12]: 21 | if (i%2!=0): 22 | continue 23 | print(i) 24 | 25 | 26 | def even_odd(number): 27 | if number%2==0: 28 | return f"{number} is even" 29 | else: 30 | return f"{number} is odd" 31 | if __name__ == "__main__": 32 | try: 33 | user_input=input("enter a number") 34 | if user_input: 35 | user_input=int(user_input) 36 | result= even_odd(user_input) 37 | print(result) 38 | else: 39 | print("No inupt provided") 40 | except ValueError: 41 | print("Enter a valid integer") 42 | except EOFError: 43 | print("No input detected") 44 | -------------------------------------------------------------------------------- /Basics/10. Functions.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Function:- A function is a block of code that performs a specific task whenever it is called. 3 | Two Types :- 4 | Built-in Functions:- The functions that are pre-defined and pre-coded in python. 5 | min(), max(), len(), sum(), type(), range(), dict(), list(), tuple(), set(), print(). 6 | User Definded Functions:- The functions we create to perform specific tasks as per our needs. 7 | Calling a function:- We call a function by the function name, followed by parameters (if any) inside the parenthesis. 8 | ''' 9 | 10 | def Out(): 11 | print("No Parameters Required") 12 | def Add(a, b): # Here a and b are Parameters and Arguments are passed to these Parameters 13 | Sum = (a+b) 14 | print(Sum) 15 | def Bigger(a, b): 16 | if(a>b): 17 | print("First Number is Bigger") 18 | else: 19 | print("Second number is Bigger") 20 | def Small(a, b): 21 | if(a>b): 22 | print("Second Number is Smaller") 23 | else: 24 | print("First Number is Smaller") 25 | 26 | 27 | a= 12 28 | b= 89 29 | Out() 30 | Bigger(a, b) 31 | Add(a, b) 32 | c= 82 33 | d= 7 34 | Small(c, d) 35 | Add(c, d) 36 | 37 | ''' 38 | Arguments in Python are of four Types: 39 | Default Arguments 40 | Keyword Arguments 41 | Variable Length Arguments 42 | Required Arguments 43 | ''' 44 | 45 | ''' 46 | Default Argument:- We provide a default value while creating a function. 47 | ''' 48 | 49 | def Add(a= 5, b= 7): 50 | print("Sum is:- ",a+b) 51 | Add() 52 | 53 | ''' 54 | Keyword Arguemnts:- Arguments with key = value. 55 | By this the interpreter recognizes the arguments by the parameter name. 56 | So the order in which the arguments are passed is not relevant. 57 | ''' 58 | 59 | def Multiplication(a, b, c): 60 | print("a= ", a, "b= ", b, "c= ", c) 61 | print("Product is ", a*b*c) 62 | Multiplication(c= 12, b= 15, a= 11) 63 | 64 | ''' 65 | Variable-length arguments:- Used to pass more arguments than defined in the actual function. 66 | ''' 67 | # Arbitrary Arguments 68 | 69 | def name(*credit): 70 | print("Hi,\n", credit[0], credit[1], credit[2]) 71 | name("Roshan ", "Rihan ", "Reetha ") 72 | 73 | # Keyword Arbitrary Arguments 74 | 75 | def name(**debit): 76 | print("Hi,\n", debit["debitor1"], debit["debitor3"], debit["debitor3"]) 77 | name(debitor1 = "Yamla ", debitor2 = "Pagla ", debitor3 = "Deewana ") 78 | 79 | ''' 80 | Required Arguments:- Conventionally, it is necessary to pass the arguments in the correct positional order 81 | and the number of arguments passed should match with arguments of function . 82 | ''' 83 | 84 | def Student(Name, Class, Roll_No): 85 | print("Hello,\n", Name, Class, Roll_No) 86 | Student(Name= "Hermione Granger", Class= "First-Year Magic Student ", Roll_No= 3) 87 | 88 | # Return Statement 89 | 90 | ''' 91 | 2 Uses - 1. End the function, 2. Send Value Back to the program 92 | ''' 93 | 94 | def Advice(a): 95 | return "Honesty is the best " + a + "!" 96 | 97 | Saying = Advice("Policy") 98 | print(Saying) 99 | 100 | # Docstring : String Literals used to define a function, method, class or module 101 | 102 | def Multiplication(a,b): 103 | '''This function takes two integers and the product of the two number is given as output''' 104 | print(a*b) 105 | Multiplication(4,6) 106 | print(Multiplication.__doc__) 107 | 108 | # PEP 8 is Python Enhancement Proposal a document that provides guidelines and best practices on how to write Python Code. 109 | # The Zen of Python consists of nineteen aphorisms, some of which favor one specific trait over another, 110 | # providing opinions about what makes your code better 111 | # Can be accessed by writing import this 112 | 113 | # Recursive Function 114 | # When a Function Repeats itself or calls some other functions. 115 | 116 | #Lambda 117 | Square= lambda a: a*a 118 | b= Square(7) 119 | print(b) 120 | 121 | Average= lambda a,b,c: (a+b+c)/3 122 | print(Average(2,4,6)) 123 | 124 | def Sqad(a,b): 125 | print(a(b)) 126 | 127 | # Anonymous Function 128 | 129 | Sqad(lambda a: a*a,4) 130 | 131 | -------------------------------------------------------------------------------- /Data Structures/11. List.py: -------------------------------------------------------------------------------- 1 | # List is an ordered collection of data that stores mutiple values. 2 | # Elements of List are called List Items and are seperated by commas and enclosed within []. 3 | # List is Mutable 4 | 5 | a=["Tungsten",53,True] 6 | print(a) 7 | print(type(a)) 8 | print(a[1]) 9 | print(a[-1]) 10 | 11 | if 't' in a[0]: 12 | print("Present") 13 | else: 14 | print("Absent") 15 | 16 | for i in a[0:3:2]: 17 | print(i,end='.') 18 | 19 | j=2 20 | x=[i+j for i in range(6) if i<5] 21 | print(x) 22 | print(2*2) 23 | 24 | # List Manipulation 25 | a=x.copy() 26 | a.append(15) 27 | a[1]=18 28 | a.insert(0,127) 29 | a.reverse() 30 | a.sort(reverse= True) 31 | print(a[4]) 32 | print(a.index(15)) 33 | print(a.count(29)) 34 | z=[57,24] 35 | a.extend(z) 36 | print(a) 37 | 38 | # Concatenation 39 | y=a+x 40 | print(y) 41 | 42 | #Replication 43 | print(z*2) 44 | -------------------------------------------------------------------------------- /Data Structures/12. Tuple.py: -------------------------------------------------------------------------------- 1 | # Tuple is an ordered collection of data that stores mutiple values. 2 | # Elements of Tuple are called Tuple Items and are seperated by commas and enclosed within (). 3 | # Tuple is Immutable 4 | 5 | x=(36) 6 | a=(27,) 7 | print(type(x)) 8 | print(type(a)) 9 | #a[0]=10 Tuples are Immutable 10 | a=(14,35,64,27,54,74,27,52,43,27) 11 | print(a[0],a.index(27)) 12 | z=a.index(27,4,8) 13 | print(z) 14 | 15 | # Type Casting 16 | b=list(a) 17 | print(type(b),b) 18 | 19 | # Concatenation 20 | d=(23,45,54,29,66) 21 | z=a+d 22 | print(z) 23 | 24 | # Replication 25 | e= d*2 26 | print(e) 27 | 28 | # Count 29 | f=e.count(29) 30 | print(f) 31 | -------------------------------------------------------------------------------- /Data Structures/13. Set.py: -------------------------------------------------------------------------------- 1 | # Set is an unordered collection of data, it stored multiple entries in a single variable. 2 | # Seperated by Commas and enclosed within {} 3 | # Sets are immutable. 4 | # Sets do not contain Duplicate Items. 5 | 6 | a=set() 7 | b={2,3,4,5,2,"Tenacious",True,2.0} 8 | print(type(a)) 9 | print(b) 10 | 11 | for i in b: 12 | print(i,end=",") 13 | print("end") 14 | 15 | if 2 in b: 16 | print(f"Yes {2*1} is present in b") 17 | else: 18 | print(f"No {2*1} is not present in b") 19 | 20 | # Manipulation 21 | 22 | a1= {23, 22, 45, 56} 23 | a2= {1, 2, 3, 4, 5, 6} 24 | a1.update(a2) 25 | a1.difference_update(a2) 26 | a3=a1.difference(a2) 27 | print(a3) 28 | print(a1) 29 | print(a1.union(a2),a1.intersection(a2)) 30 | a1.update(a2) 31 | a3= a1.symmetric_difference(a2) 32 | a1.intersection_update(a2) 33 | print(a1) 34 | print(a3) 35 | 36 | ''' 37 | union() 38 | update() 39 | intersection 40 | intersectin_update() 41 | symmetric_difference 42 | symmetric_difference_update() 43 | difference() 44 | difference_update() 45 | ''' 46 | 47 | # IN- Built Methods 48 | print(a1.isdisjoint(a3)) 49 | print(a1.isdisjoint(a2)) 50 | print(a1.issuperset(a2)) 51 | print(a1.issubset(a2)) 52 | 53 | a1.add(11) 54 | a1.remove(3) 55 | a1.discard(21)# No Error 56 | print(a1) 57 | a10= a1.pop() 58 | print(a10) 59 | del a10 60 | a3.clear() 61 | print(a3) -------------------------------------------------------------------------------- /Data Structures/14. Dictionary.py: -------------------------------------------------------------------------------- 1 | # Dictionary is an ordered collection of data that stores multiple values 2 | # Key- Value Pair having , in between and enclosed in {} 3 | 4 | a={ 5 | "Ram": "Mediator", 6 | "Dhoni": "Marketing", 7 | "Shyam": "Client" 8 | } 9 | 10 | print(a["Dhoni"]) 11 | print(a.get("Ram"))# Does not give error in case of controversy 12 | print(a.keys()) 13 | print(a.values()) 14 | print(a.items()) 15 | a.pop("Shyam") 16 | a.popitem() 17 | del a["Ram"] 18 | 19 | for x,y in a.items(): 20 | print(f"The way to print {x} along with the right {y} consistency is key.") 21 | 22 | b={ 23 | "Hari":"Task", 24 | "Mohan":"Analyst" 25 | } 26 | a.update(b) 27 | print(a) 28 | b.clear() 29 | print(b) 30 | del b -------------------------------------------------------------------------------- /Error Handling/15. Exception Handling.py: -------------------------------------------------------------------------------- 1 | a= input("Enter the number:- ") 2 | print(f"The counting to {a} is:-") 3 | try: 4 | for i in range(int(a)): 5 | print(i) 6 | except Exception as a: 7 | print(a) 8 | 9 | b= input("For Resetting:- ") 10 | try: 11 | for i in range(5): 12 | print(int(b)) 13 | except: 14 | print("Wrong Input") 15 | print("End of Code") 16 | 17 | try: 18 | a=[2,3,4] 19 | b=int(input("Enter the number")) 20 | print(5*a[b]) 21 | except IndexError: 22 | print("Wrong Input") 23 | except ValueError: 24 | print("Not an Integer") 25 | finally: 26 | print("Terminate") -------------------------------------------------------------------------------- /Error Handling/16. Customized Errors.py: -------------------------------------------------------------------------------- 1 | a=[2,3,4] 2 | b=int(input("Enter the number:-")) 3 | if(b<0 or b>2): 4 | raise IndexError("Index not available") 5 | print(5*a[b]) 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 SaurabhSSB 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Module and File Handling/17. Import.py: -------------------------------------------------------------------------------- 1 | # import math 2 | 3 | import math as m 4 | x=m.sqrt(144) 5 | print(x) 6 | 7 | from math import * 8 | a=sqrt(64) 9 | print(a) 10 | 11 | from math import sqrt as q 12 | b=q(121) 13 | print(b) 14 | 15 | import math as y 16 | print(dir(y)) 17 | print(y.erfc) 18 | print(type(y.erfc)) 19 | 20 | from Afunc import * 21 | Multiplication(10, 11, 12) 22 | -------------------------------------------------------------------------------- /Module and File Handling/18. File Operations.py: -------------------------------------------------------------------------------- 1 | with open("ABC.txt","a") as a: 2 | a.write("\nFinally able to do operation on file. Thanks Python!") 3 | 4 | a= open("ABC.txt","r") 5 | r= a.read() 6 | print(r) 7 | a.close() 8 | 9 | # r mode- Read Default 10 | # w mode- Write 11 | # a mode- Append 12 | # x mode- Create 13 | # t mode- Text Default 14 | # b mode- Binary Jpg, Image, Pdf, exe 15 | 16 | f= open("ABC.txt","r") 17 | while True: 18 | line= f.readline() 19 | if not line: 20 | break 21 | print(line) 22 | 23 | x= open("ABCD.txt","w") 24 | y= ['one\n','two\n','three\n'] 25 | x.writelines(y) 26 | x.close() 27 | 28 | with open("ABC.txt","r") as a: 29 | print(type(a)) 30 | a.seek(5) 31 | print(a.tell()) 32 | x=a.read(6) 33 | print(a.tell()) 34 | print(x) 35 | 36 | with open("z_is.txt",'w') as b: 37 | b.write("Relay the Message.") 38 | b.truncate(6) 39 | with open("z_is.txt",'r') as c: 40 | print(c.read()) -------------------------------------------------------------------------------- /Module and File Handling/19. Map.py: -------------------------------------------------------------------------------- 1 | # Map- Value Takes Function 2 | 3 | def Increment(x): 4 | return(x+1) 5 | 6 | a=[12, 10, 11, 14, 19, 21, 42] 7 | b=list(map(Increment, a)) 8 | print(b) 9 | 10 | c=list(map(lambda x:x+1,a)) 11 | print(c) 12 | 13 | # Filter- True or False Takes Predicate 14 | d=list(filter(lambda x: x<21, c)) 15 | print(d) 16 | 17 | # Reduce- Single Value Takes Function 18 | from functools import reduce 19 | 20 | x=[11, 34, 5, 27, 53, 22] 21 | y=reduce( lambda x1, x2: x1+ x2, x) 22 | print(y) -------------------------------------------------------------------------------- /Object Oriented Programming/20. OOP.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Object- Oriented Programming in Python is to use classes and objects to represent real- world concepts and entities. 3 | Object- Oriented Programming is used to map real world entities. 4 | Entry- Class/ Blue- Print/ Template- Properties and methods that an object in class will have 5 | Students- Object/ Entity- Instance of Class- contains it's own data and methods 6 | Python follows PascalCase for class names (first letter capitalized). 7 | ''' 8 | class Student: 9 | roll_no= 10 10 | name= "Saurabh Singh Bhandari" 11 | graduation= "BTech" 12 | def info(self): 13 | print(f"Roll No. {self.roll_no} name is {self.name} he has a {self.graduation} degree") 14 | 15 | x= Student() 16 | x. name= "Nittin" 17 | x. roll_no= 16 18 | x.info() 19 | 20 | a= [10, 14, 16, 27, 36, 49] 21 | print(dir(a)) 22 | print(a.__class__) 23 | 24 | print(x.__dict__) 25 | print(help(Student)) -------------------------------------------------------------------------------- /Object Oriented Programming/21. Constructor.py: -------------------------------------------------------------------------------- 1 | # 2 types of Constructors- Parameterized and Default 2 | 3 | class Student: 4 | def __init__(self, a, b, c): 5 | self.roll_no= a 6 | self.name= b 7 | self.graduation= c 8 | def info(self): 9 | print(f"Roll No. {self.roll_no} name is {self.name} he has a {self.graduation} degree") 10 | 11 | x= Student( 10, "Saurabh Singh Bhandari", "BTech") 12 | y= Student( 16, "Nittin", "BTech") 13 | x.info() 14 | y.info() 15 | 16 | # Instance & Class Variable 17 | 18 | class Student: 19 | School= "Kendriya Vidyalaya" # Class Variable 20 | Student_no= 0 21 | def __init__ (self, roll_no,name): 22 | self.roll_no= roll_no 23 | self.name= name 24 | self._class= 12 # Instance Varaible 25 | Student.Student_no+= 1 26 | def show(self): 27 | print(f"{self.name} Roll No.{self.roll_no} School {Student.School} once studied in {self._class} class in {self.School}") 28 | 29 | a= Student(10, "Saurabh Singh Bhandari") 30 | print(Student.School) 31 | a.show() 32 | print(f"Total Student enrolled= {Student.Student_no}") -------------------------------------------------------------------------------- /Object Oriented Programming/22. Decorators.py: -------------------------------------------------------------------------------- 1 | def decorate(fx): 2 | def mfx(*args,**kwargs): 3 | '''*args= argument as tuple, **kwargs= argument as dictionary as key- value pairs''' 4 | print("your choice has been registered") 5 | fx(*args,**kwargs) 6 | print("Thanks a lot!") 7 | return(mfx) 8 | 9 | 10 | @decorate 11 | def check(): 12 | print("Only for Demo") 13 | 14 | def alternative(): 15 | print("Only as an Alternative") 16 | 17 | def add(a,b): 18 | print(a + b) 19 | 20 | @decorate 21 | def product(a,b): 22 | print(a * b) 23 | 24 | def remainder(a,b): 25 | print(a / b) 26 | 27 | def difference(a,b): 28 | print(a - b) 29 | 30 | check() 31 | 32 | decorate(alternative)() 33 | decorate(add)(5,6) 34 | 35 | product(2,4) -------------------------------------------------------------------------------- /Object Oriented Programming/23. Getters and Setters.py: -------------------------------------------------------------------------------- 1 | # Python program showing a use 2 | # of get() and set() method in 3 | # normal function 4 | 5 | class Geek: 6 | def __init__(self, age = 0): 7 | self._age = age 8 | 9 | # getter method 10 | def get_age(self): 11 | return self._age 12 | 13 | # setter method 14 | def set_age(self, x): 15 | self._age = x 16 | 17 | raj = Geek() 18 | 19 | # setting the age using setter 20 | raj.set_age(21) 21 | 22 | # retrieving age using getter 23 | print(raj.get_age()) 24 | 25 | print(raj._age) 26 | 27 | # Python program showing a 28 | # use of property() function 29 | 30 | class Geeks: 31 | def __init__(self): 32 | self._age = 0 33 | 34 | # function to get value of _age 35 | def get_age(self): 36 | print("getter method called") 37 | return self._age 38 | 39 | # function to set value of _age 40 | def set_age(self, a): 41 | print("setter method called") 42 | self._age = a 43 | 44 | # function to delete _age attribute 45 | def del_age(self): 46 | del self._age 47 | 48 | age = property(get_age, set_age, del_age) 49 | 50 | mark = Geeks() 51 | 52 | mark.age = 10 53 | 54 | print(mark.age) 55 | 56 | # Python program showing the use of 57 | # @property 58 | 59 | class Geeks: 60 | def __init__(self): 61 | self._age = 0 62 | 63 | # using property decorator 64 | # a getter function 65 | @property 66 | def age(self): 67 | print("getter method called") 68 | return self._age 69 | 70 | # a setter function 71 | @age.setter 72 | def age(self, a): 73 | if(a < 18): 74 | raise ValueError("Sorry you age is below eligibility criteria") 75 | print("setter method called") 76 | self._age = a 77 | 78 | mark = Geeks() 79 | 80 | mark.age = 19 81 | 82 | print(mark.age) 83 | 84 | class Person: 85 | def __init__(self, name, age): 86 | self._name = name 87 | self._age = age 88 | 89 | @property 90 | def name(self): 91 | return self._name 92 | 93 | @name.setter 94 | def name(self, name): 95 | if not isinstance(name, str): 96 | raise TypeError("Name must be a string") 97 | self._name = name 98 | 99 | @property 100 | def age(self): 101 | return self._age 102 | 103 | @age.setter 104 | def age(self, age): 105 | if not isinstance(age, int) or age < 0: 106 | raise ValueError("Age must be a positive integer") 107 | self._age = age 108 | 109 | ''' 110 | In object-oriented programming, setter and getter methods are used to control access to an object's properties. 111 | Getters are used to access the value of an object's properties. Used to return the value of a specific property and 112 | conventionally defined with @property decorator. 113 | We need Setters which can be added by decorating method with @property_name.setter, this is done because getters do not take any 114 | parameters and we cannot set the value through getter method. 115 | the main purpose of using getters and setters in object-oriented programs is to ensure data encapsulation. 116 | 117 | Getters and Setters in python are often used when: 118 | - We use getters & setters to add validation logic around getting and setting a value. 119 | - To avoid direct access of a class field i.e. private variables cannot be accessed directly or modified by external user. 120 | 121 | Encapsulate data: Hide internal implementation details. 122 | Validate input: Ensure data integrity. 123 | Provide flexibility: Allow for future modifications without affecting external code. 124 | Readability: Well-defined getter and setter methods can improve code readability and maintainability. 125 | 126 | Explanation: 127 | 128 | Private Attributes: 129 | Attributes prefixed with an underscore (_) are conventionally treated as private. This indicates that they should be accessed and modified only through the defined methods. 130 | Getter Methods: 131 | 132 | These methods return the value of a private attribute. 133 | get_name() and get_age() are examples of getter methods. 134 | 135 | Setter Methods: 136 | These methods set the value of a private attribute. 137 | set_name() and set_age() are examples of setter methods. 138 | The set_age() method demonstrates input validation. 139 | 140 | In Conclusion, Getters are a convenient way to access the values of an object's properties, while keeping the internal representation 141 | of the property hidden. This can be useful for data encapsulation and data validation. 142 | ''' 143 | 144 | class MyClass: 145 | def __init__(self,value): 146 | self. _value= value 147 | def show(self): 148 | print(f"{self._value} is a private attribute, thus we are using setter and getter to get access to it.") 149 | 150 | @property 151 | def value(self): 152 | return(self._value) 153 | 154 | @value.setter 155 | def value(self,value): 156 | self._value= value 157 | 158 | a= MyClass(11) 159 | a.show() 160 | a.value= 5 161 | print(a.value) 162 | a.show() -------------------------------------------------------------------------------- /Object Oriented Programming/24. Inheritance.py: -------------------------------------------------------------------------------- 1 | class Entry: 2 | def __init__(self, roll_no, name): 3 | self.roll_no= roll_no 4 | self.name= name 5 | def show(self): 6 | print(f"Roll No.:- {self.roll_no} and Name {self.name}") 7 | 8 | class Course(Entry): 9 | # INHERITANCE 10 | def show(self): 11 | print(f"Roll No.:- {self.roll_no} and Name {self.name} has done BTech in Computer Science") 12 | 13 | 14 | a=Entry(10, "Saurabh Singh Bhandari") 15 | a.show() 16 | b=Course(11, "Nittin") 17 | b.show() 18 | 19 | class Entry: 20 | def __init__(self, roll_no, name): 21 | self.roll_no= roll_no 22 | self.name= name 23 | def show(self): 24 | print(f"Roll No.:- {self.roll_no} and Name {self.name}") 25 | 26 | class Course(Entry): 27 | # INHERITANCE 28 | def show(self): 29 | print(f"Roll No.:- {self.roll_no} and Name {self.name} has done BTech in Computer Science") 30 | super().show() 31 | # The super() keyword in Python is used to refer to the parent class 32 | 33 | 34 | class Computer_lab(Entry): 35 | def __init__(self, roll_no, name, language): 36 | super().__init__(roll_no, name) 37 | self.language= language 38 | 39 | a=Entry(10, "Saurabh Singh Bhandari") 40 | a.show() 41 | b=Course(11, "Nittin") 42 | b.show() 43 | c=Computer_lab(23,"Chaya" , "Java") 44 | print(c.language) 45 | 46 | 47 | -------------------------------------------------------------------------------- /Object Oriented Programming/25. Access Specifiers or Access Modifiers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Access specifiers or access modifiers in python programming are used to limit the access of class variables and class methods outside 3 | of class while implementing the concepts of inheritance. 4 | Three Types:- 5 | Public access modifier 6 | Private access modifier 7 | Protected access modifier 8 | ''' 9 | # Public 10 | class Student: 11 | def __init__(self,roll_no, name, graduation): 12 | self.roll_no= roll_no 13 | self.name= name 14 | self.graduation= graduation 15 | def info(self): 16 | print(f"Roll No. {self.roll_no} name {self.name} has a {self.graduation} degree") 17 | 18 | x= Student(10, "Saurabh Singh Bhandari", "BTech") 19 | x.info() 20 | 21 | # Private 22 | class Student: 23 | def __init__(self,roll_no, name, graduation): 24 | self.roll_no= roll_no 25 | self.__name= name 26 | self.graduation= graduation 27 | def info(self): 28 | print(f"Roll No. {self.roll_no} name {self.__name} has a {self.graduation} degree") 29 | 30 | x= Student(10, "Saurabh Singh Bhandari", "BTech") 31 | x.info() 32 | print(x._Student__name) # Name Mangling 33 | 34 | # Protected Access Modifier 35 | class Student: 36 | def __init__(self,roll_no, name, graduation): 37 | self.roll_no= roll_no 38 | self._name= name 39 | self.graduation= graduation 40 | def info(self): 41 | print(f"Roll No. {self.roll_no} name {self._name} has a {self.graduation} degree") 42 | 43 | x= Student(10, "Saurabh Singh Bhandari", "BTech") 44 | x.info() 45 | print(x._name) # Name Mangling 46 | 47 | print(x.__dir__()) -------------------------------------------------------------------------------- /Object Oriented Programming/26. Static Method.py: -------------------------------------------------------------------------------- 1 | class Calci: 2 | def __init__(self, a): 3 | self.num= a 4 | 5 | def add(self, b): 6 | self.num= self.num+ b 7 | 8 | @staticmethod 9 | def product(x,y): 10 | return(x*y) 11 | 12 | a= Calci(10) 13 | print(a.num) 14 | 15 | a.add(15) 16 | print(a.num) 17 | 18 | b= Calci.product(3,5) 19 | c= a.product(5,5) 20 | print(b,c) -------------------------------------------------------------------------------- /Object Oriented Programming/27. Class Method.py: -------------------------------------------------------------------------------- 1 | class Student: 2 | School= "Kendriya Vidyalaya" 3 | def __init__(self, roll_no, name): 4 | self.roll_no= roll_no 5 | self.name= name 6 | 7 | def show(self): 8 | print(f"Name {self.name} Roll No.{self.roll_no} studied at {Student.School}") 9 | 10 | @classmethod 11 | def change(cls, School): 12 | cls.School = School 13 | 14 | Student.change("PM Shri") 15 | a= Student(10, "Saurabh Singh Bhandari") 16 | a.show() 17 | print(Student.School) 18 | 19 | # Class Method as Alternative Constructor 20 | 21 | class Student: 22 | def __init__(self, name, roll_no): 23 | self.name = name 24 | self.roll_no = roll_no 25 | 26 | @classmethod 27 | def fromStr(cls, data): 28 | return cls(data.split(",")[0], int(string.split(",")[1])) 29 | 30 | e1 = Student("Harry", 12000) 31 | print(e1.name) 32 | print(e1.roll_no) 33 | 34 | string = "John,12000" 35 | e2 = Student.fromStr(string) 36 | print(e2.name) 37 | print(e2.roll_no) 38 | -------------------------------------------------------------------------------- /Object Oriented Programming/28.Magic- Dunder Method.py: -------------------------------------------------------------------------------- 1 | ''' 2 | These are special methods that we can define in our classes, and when invoked, they give us a powerful way to 3 | manipulate objects and their behaviour. 4 | ''' 5 | 6 | class Student: 7 | def __init__(self,name): 8 | self.name=name 9 | 10 | def __len__(self): 11 | x=0 12 | for i in self.name: 13 | x+= 1 14 | return x 15 | 16 | def __str__(self): 17 | return f"Student {self.name}" 18 | 19 | def __repr__(self): 20 | return f"Student('{self.name}')" 21 | 22 | def __call__(self): 23 | print("SaurabhSinghBhandariSSB") 24 | 25 | a= Student("Saurabh Singh Bhandari") 26 | print(len(a)) 27 | print(str(a)) 28 | print(repr(a)) 29 | a() 30 | 31 | # Operator Overloading 32 | class Vector: 33 | def __init__(self, i, j, k): 34 | self.i = i 35 | self.j = j 36 | self.k = k 37 | 38 | def __str__(self): 39 | return f"{self.i}i + {self.j}j + {self.k}k" 40 | 41 | def __add__(self, x): 42 | return Vector(self.i + x.i, self.j+x.j, self.k+x.k) 43 | v1 = Vector(3, 5, 6) 44 | print(v1) 45 | 46 | v2 = Vector(1, 2, 9) 47 | print(v2) 48 | 49 | print(v1 + v2) 50 | print(type(v1 + v2)) -------------------------------------------------------------------------------- /Object Oriented Programming/29. Overriding.py: -------------------------------------------------------------------------------- 1 | class Shape: 2 | def __init__(self, x, y): 3 | self.x = x 4 | self.y = y 5 | 6 | def area(self): 7 | return self.x * self.y 8 | 9 | class Circle(Shape): 10 | def __init__(self, radius): 11 | self.radius = radius 12 | super().__init__(radius, radius) 13 | 14 | def area(self): 15 | return 3.14 * super().area() 16 | 17 | rec = Shape(3, 5) 18 | print(rec.area()) 19 | 20 | c = Circle(5) 21 | print(c.area()) -------------------------------------------------------------------------------- /Object Oriented Programming/30. Single Inheritance.py: -------------------------------------------------------------------------------- 1 | # Single Inheritance 2 | class Entry: 3 | def __init__(self,roll_no, name, stream): 4 | self.roll_no= roll_no 5 | self.name= name 6 | self.stream= stream 7 | def open(self): 8 | print(f"{self.name} Rollno.{self.roll_no}is s student of {self.stream} in BTech") 9 | 10 | class Python(Entry): 11 | def __init__(self, roll_no, name, age): 12 | Entry.__init__(self, roll_no, name, stream= "Computer Science") 13 | self.age= age 14 | def open(self): 15 | print(f"{self.name} Rollno. {self.roll_no} of {self.stream} of {self.age} age in BTech is eligible for Python Workshop") 16 | 17 | a= Entry(10, "Saurabh Singh Bhandari", "Computer Science") 18 | b= Python(11, "SaurabhSSB", 22) 19 | a.open() 20 | b.open() -------------------------------------------------------------------------------- /Object Oriented Programming/31. Multiple Inheritance.py: -------------------------------------------------------------------------------- 1 | # Multiple Inheritance 2 | # MRO- Method Resolution Order 3 | class Entry: 4 | def __init__(self, roll_no, name): 5 | self.roll_no= roll_no 6 | self.name= name 7 | def open(self): 8 | print(f"{self.name} Rollno. {self.roll_no} is eligible for admission") 9 | def approved(self): 10 | print(f"{self.name} is approved and is given Entry.") 11 | 12 | class Stream: 13 | def __init__(self, name, age, stream): 14 | self.name= name 15 | self.age= age 16 | self.stream= stream 17 | def open(self): 18 | print(f"{self.name} age {self.age} is eligible for {self.stream} in BTech") 19 | def approved(self): 20 | print(f"{self.name} is approved in this Stream.") 21 | 22 | class Library (Entry, Stream): 23 | def __init__(self, roll_no, name, stream): 24 | super().__init__(roll_no, name) 25 | self.stream= stream 26 | def open(self): 27 | print(f"{self.name} Rollno. {self.roll_no} of {self.stream} Stream is eligible to take books from here.") 28 | 29 | a= Entry(10,"Saurabh Singh Bhandari") 30 | b= Stream("Saurabh Singh Bhandari", 22, "Computer Science") 31 | c= Library(10,"Saurabh Singh Bhandari", "Computer Science") 32 | a.open() 33 | b.open() 34 | c.open() 35 | c.approved() 36 | 37 | print(Library.mro()) -------------------------------------------------------------------------------- /Object Oriented Programming/32. Multilevel Inheritance.py: -------------------------------------------------------------------------------- 1 | class Entry: 2 | Entrance= "Permitted" 3 | def __init__(self, name, qualification): 4 | self.name=name 5 | self.qualification=qualification 6 | def open(self): 7 | print(f"{self.name} has done {self.qualification} and is {Entry.Entrance}") 8 | 9 | class Class(Entry): 10 | def __init__(self, roll_no, name, course): 11 | Entry.__init__(self, name, qualification= "Twelfth") 12 | self.roll_no= roll_no 13 | self.course= course 14 | def open(self): 15 | #Entry.open(self) 16 | print(f"{self.name} Rollno. {self.roll_no} has done {self.qualification} and is going to enroll in {self.course}") 17 | 18 | 19 | class Stream(Class): 20 | def __init__(self, roll_no, name, stream): 21 | Class.__init__(self, roll_no, name, course= "Btech") 22 | self.stream= stream 23 | def open(self): 24 | Class.open(self) 25 | print(f"{self.name} of Rollno. {self.roll_no} from {self.course} is opting for {self.stream}") 26 | 27 | a= Stream( 10, "Saurabh Singh Bhandari", "Computer Science") 28 | a.open() 29 | 30 | c= Class(10, "Saurabh Singh Bhandari", "BTech") 31 | c.open() 32 | b=Entry("Saurabh", "Twelfth") 33 | b.open() 34 | 35 | print(Class.mro()) -------------------------------------------------------------------------------- /Object Oriented Programming/33. Hybrid Inheritance.py: -------------------------------------------------------------------------------- 1 | class one: 2 | pass 3 | class two(one): 4 | pass 5 | class three(one): 6 | pass 7 | class four(two, three): 8 | pass 9 | -------------------------------------------------------------------------------- /Object Oriented Programming/34. Hierarchical Inheritance.py: -------------------------------------------------------------------------------- 1 | # Tree like structure 2 | 3 | class one: 4 | pass 5 | class two(one): 6 | pass 7 | class three(one): 8 | pass 9 | class four(one): 10 | pass 11 | class five(one): 12 | pass -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Python Mastery Roadmap** 2 | 3 | 🎯 **Master Python from Basics to Advanced Concepts** 4 | 5 | Welcome to the **Python Mastery Roadmap** repository! This project provides a structured learning path for Python, covering everything from fundamental concepts to advanced programming topics. Whether you're a beginner or refining your skills, this roadmap will guide you every step of the way. 🚀 6 | 7 | --- 8 | 9 | ## 📂 **Repository Structure** 10 | 11 | The repository is organized into directories based on topics, each containing Python scripts to help you learn effectively. 12 | 13 | ### **1. Basics** 14 | - [01. Getting familiar with Python.py](Basics/01.%20Getting%20familiar%20with%20python.py) 15 | - [02. Variables and Data Types.py](Basics/02.%20Variables%20and%20Data%20Types.py) 16 | - [03. Operators.py](Basics/03.%20Operators.py) 17 | - [04. Strings.py](Basics/04.%20Strings.py) 18 | - [05. If-elif-else.py](Basics/05.%20If-%20elif-%20else.py) 19 | - [06. Match Case.py](Basics/06.%20Match%20Case.py) 20 | - [07. For Loop.py](Basics/07.%20For%20Loop.py) 21 | - [08. While Loops.py](Basics/08.%20While%20Loops.py) 22 | - [09. Break and Continue.py](Basics/09.%20Break%20and%20Continue.py) 23 | - [10. Functions.py](Basics/10.%20Functions.py) 24 | 25 | ### **2. Data Structures** 26 | - [11. List.py](Data%20Structures/11.%20List.py) 27 | - [12. Tuple.py](Data%20Structures/12.%20Tuple.py) 28 | - [13. Set.py](Data%20Structures/13.%20Set.py) 29 | - [14. Dictionary.py](Data%20Structures/14.%20Dictionary.py) 30 | 31 | ### **3. Error Handling** 32 | - [15. Exception Handling.py](Error%20Handling/15.%20Exception%20Handling.py) 33 | - [16. Customized Errors.py](Error%20Handling/16.%20Customized%20Errors.py) 34 | 35 | ### **4. Modules and File Handling** 36 | - [17. Import.py](Modules%20and%20File%20Handling/17.%20Import.py) 37 | - [18. File Operations.py](Modules%20and%20File%20Handling/18.%20File%20Operations.py) 38 | - [19. Map.py](Modules%20and%20File%20Handling/19.%20Map.py) 39 | 40 | ### **5. Object-Oriented Programming** 41 | - [20. OOP.py](Object%20Oriented%20Programming/20.%20OOP.py) 42 | - [21. Constructor.py](Object%20Oriented%20Programming/21.%20Constructor.py) 43 | - [22. Decorators.py](Object%20Oriented%20Programming/22.%20Decorators.py) 44 | - [23. Getters and Setters.py](Object%20Oriented%20Programming/23.%20Getters%20and%20Setters.py) 45 | - [24. Inheritance.py](Object%20Oriented%20Programming/24.%20Inheritance.py) 46 | - [25. Access Specifiers or Access Modifiers.py](Object%20Oriented%20Programming/25.%20Access%20Specifiers%20or%20Access%20Modifiers.py) 47 | - [26. Static Method.py](Object%20Oriented%20Programming/26.%20Static%20Method.py) 48 | - [27. Class Method.py](Object%20Oriented%20Programming/27.%20Class%20Method.py) 49 | - [28. Magic- Dunder Method.py](Object%20Oriented%20Programming/28.%20Magic-%20Dunder%20Method.py) 50 | - [29. Overriding.py](Object%20Oriented%20Programming/29.%20Overriding.py) 51 | - [30. Single Inheritance.py](Object%20Oriented%20Programming/30.%20Single%20Inheritance.py) 52 | - [31. Multiple Inheritance.py](Object%20Oriented%20Programming/31.%20Multiple%20Inheritance.py) 53 | - [32. Multilevel Inheritance.py](Object%20Oriented%20Programming/32.%20Multilevel%20Inheritance.py) 54 | - [33. Hybrid Inheritance.py](Object%20Oriented%20Programming/33.%20Hybrid%20Inheritance.py) 55 | - [34. Hierarchical Inheritance.py](Object%20Oriented%20Programming/34.%20Hierarchical%20Inheritance.py) 56 | 57 | ### **6. Time Module** 58 | - [35. Time Module.py](Time%20Module/35.%20Time%20Module.py) 59 | 60 | --- 61 | 62 | ## ✨ **Features** 63 | - **Structured Learning Path**: Topics arranged systematically for gradual skill-building. 64 | - **Hands-On Code Examples**: Each file contains practical examples and exercises. 65 | - **Focus on Fundamentals**: Strong emphasis on understanding Python's core concepts. 66 | - **Advanced Concepts**: Learn advanced programming paradigms like OOP, decorators, and inheritance. 67 | 68 | --- 69 | 70 | ## 🚀 **Getting Started** 71 | 72 | ### **Step 1: Clone the Repository** 73 | ```bash 74 | git clone https://github.com/SaurabhSSB/Python-Mastery-Roadmap.git 75 | 76 | ``` 77 | ### **Step 2: Navigate Through the Topics** 78 | Explore the folders to find the topic you're learning. 79 | Open the .py file in your code editor or IDE. 80 | 81 | ### **Step 3: Run and Experiment** 82 | Run the scripts using Python 3.x. 83 | Modify the examples to test your understanding. 84 | 85 | ### 📖 **Prerequisites** 86 | Python 3.x installed on your system. 87 | A code editor or IDE like VSCode, PyCharm, or Jupyter Notebook. 88 | 89 | ### 🤝 **Contributing** 90 | I always welcome contributions! 91 | 92 | Fix errors or typos. 93 | Add new examples or topics. 94 | Submit a pull request. 95 | 96 | ### 🛠️ **License** 97 | This repository is licensed under the MIT License. Feel free to use it for learning or teaching purposes. 98 | 99 | ### 📧 **Contact** 100 | For any queries or suggestions, feel free to reach out: 101 | **Email**: [saurabhsinghbhandarissb@gmail.com] 102 | **GitHub**: https://github.com/SaurabhSSB 103 | 104 | 105 | -------------------------------------------------------------------------------- /Time Module/35. Time Module.py: -------------------------------------------------------------------------------- 1 | # Built- In Module for time related operations 2 | import time 3 | 4 | def sum(x, y): 5 | print(x+ y) 6 | 7 | def product(x, y): 8 | print(x*y) 9 | 10 | t= time.time() 11 | sum(10,11) 12 | t2=time.time()- t 13 | t1= time.time() 14 | product(4,6) 15 | print(t2) 16 | print(time.time()-t1) 17 | 18 | # lambda addition 19 | a= time.time() 20 | add= lambda x, y: x+ y 21 | add(4,6) 22 | a1=time.time()- t 23 | print(a1) 24 | 25 | print("Saurabh Singh Bhandari") 26 | time.sleep(6) 27 | print("Is a wonderful person.") 28 | 29 | x= time.localtime() 30 | f= time.strftime("%Y-%M-%D %H:%M:%S", x) 31 | print(f) --------------------------------------------------------------------------------