├── .gitignore ├── Day-01 ├── 01-shell-vs-python.md ├── 02-hello-world.py └── README.md ├── Day-02 ├── 01-data-types.md ├── 02-strings.md ├── 03-numeric.md ├── 04-regex.md ├── README.md ├── examples │ ├── 01-string-concat.py │ ├── 01-string-len.py │ ├── 01-string-lowercase.py │ ├── 01-string-replace.py │ ├── 01-string-split.py │ ├── 01-string-strip.py │ ├── 01-string-substring.py │ ├── 02-float.py │ ├── 02-int.py │ ├── 03-regex-findall.py │ ├── 03-regex-match.py │ ├── 03-regex-replace.py │ ├── 03-regex-search.py │ └── 03-regex-split.py └── strings.py ├── Day-03 ├── README.md ├── keywords.md └── variables.md ├── Day-04 └── README.md ├── Day-05 └── README.md ├── Day-06 ├── 01-Notes │ ├── Arithmetic Operators.md │ ├── Assignment Operators.md │ ├── Bitwise Operators.md │ ├── Identity Operators.md │ ├── Logical Operators.md │ ├── Membership Operators.md │ ├── Precedence Operators.md │ └── Relational Operators.md ├── 02-Assignment │ ├── 01-Questions │ │ └── assignment.md │ └── 02-Answers │ │ ├── task-01-answer.py │ │ ├── task-02-answer.py │ │ ├── task-03-answer.py │ │ ├── task-04-answer.py │ │ └── task-05-answer.py └── README.md ├── Day-07 └── README.md ├── Day-08 ├── 01-Notes │ ├── 01-list.md │ ├── 02-tuple.md │ ├── 03-list-vs-tuple.md │ └── 04-faq.md ├── 02-Assigment │ ├── 01-list-questions.md │ └── 02-list-answers.md └── README.md ├── Day-09 ├── 01-loops.md ├── 02-loop-controls.md ├── 03-for-loop-devops-usecases.md ├── 04-while-loop-devops-usecases.md └── README.md ├── Day-10 ├── 01-convert-string-to-list.py ├── 02-main-construct.py ├── 03-list-files-in-folders.py └── README.md ├── Day-11 ├── 01-dictionaries.md ├── 02-sets.md ├── 03-lists-vs-sets.md ├── 04-demo-github-integration.py ├── 04-practicals.md ├── 04-practicals.py └── README.md ├── Day-12 ├── server.conf └── update_server.py ├── Day-13 └── README.md ├── Day-14 ├── README.md └── examples │ ├── create-jira.py │ └── list_projects.py ├── Day-15 ├── README.md ├── examples │ └── hello-world.py └── github-jira.py ├── Day-16 └── README.md ├── Day-17 └── README.md ├── Day-18 └── README.md ├── Day-19 └── README.md ├── LICENSE ├── README.md └── simple-python-app ├── app.py └── requirements.txt /.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 | -------------------------------------------------------------------------------- /Day-01/01-shell-vs-python.md: -------------------------------------------------------------------------------- 1 | Certainly! The choice between using shell scripting and Python in DevOps depends on the specific task or problem you're trying to solve. Both have their strengths and are suitable for different scenarios. Here are some guidelines to help you decide when to use each: 2 | 3 | **Use Shell Scripting When:** 4 | 5 | 1. **System Administration Tasks:** Shell scripting is excellent for automating routine system administration tasks like managing files, directories, and processes. You can use shell scripts for tasks like starting/stopping services, managing users, and basic file manipulation. 6 | 7 | 2. **Command Line Interactions:** If your task primarily involves running command line tools and utilities, shell scripting can be more efficient. It's easy to call and control these utilities from a shell script. 8 | 9 | 3. **Rapid Prototyping:** If you need to quickly prototype a solution or perform one-off tasks, shell scripting is usually faster to write and execute. It's great for ad-hoc tasks. 10 | 11 | 4. **Text Processing:** Shell scripting is well-suited for tasks that involve text manipulation, such as parsing log files, searching and replacing text, or extracting data from text-based sources. 12 | 13 | 5. **Environment Variables and Configuration:** Shell scripts are useful for managing environment variables and configuring your system. 14 | 15 | **Use Python When:** 16 | 17 | 1. **Complex Logic:** Python is a full-fledged programming language and is well-suited for tasks that involve complex logic, data structures, and algorithms. If your task requires extensive data manipulation, Python can be a more powerful choice. 18 | 19 | 2. **Cross-Platform Compatibility:** Python is more platform-independent than shell scripting, making it a better choice for tasks that need to run on different operating systems. 20 | 21 | 3. **API Integration:** Python has extensive libraries and modules for interacting with APIs, databases, and web services. If your task involves working with APIs, Python may be a better choice. 22 | 23 | 4. **Reusable Code:** If you plan to reuse your code or build larger applications, Python's structure and modularity make it easier to manage and maintain. 24 | 25 | 5. **Error Handling:** Python provides better error handling and debugging capabilities, which can be valuable in DevOps where reliability is crucial. 26 | 27 | 6. **Advanced Data Processing:** If your task involves advanced data processing, data analysis, or machine learning, Python's rich ecosystem of libraries (e.g., Pandas, NumPy, SciPy) makes it a more suitable choice. -------------------------------------------------------------------------------- /Day-01/02-hello-world.py: -------------------------------------------------------------------------------- 1 | print("Hello, World!") 2 | -------------------------------------------------------------------------------- /Day-01/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-01/README.md -------------------------------------------------------------------------------- /Day-02/01-data-types.md: -------------------------------------------------------------------------------- 1 | # Data Types 2 | 3 | In programming, a data type is a classification or categorization that specifies which type of value a variable can hold. Data types are essential because they determine how data is stored in memory and what operations can be performed on that data. Python, like many programming languages, supports several built-in data types. Here are some of the common data types in Python: 4 | 5 | 1. **Numeric Data Types:** 6 | - **int**: Represents integers (whole numbers). Example: `x = 5` 7 | - **float**: Represents floating-point numbers (numbers with decimal points). Example: `y = 3.14` 8 | - **complex**: Represents complex numbers. Example: `z = 2 + 3j` 9 | 10 | 2. **Sequence Types:** 11 | - **str**: Represents strings (sequences of characters). Example: `text = "Hello, World"` 12 | - **list**: Represents lists (ordered, mutable sequences). Example: `my_list = [1, 2, 3]` 13 | - **tuple**: Represents tuples (ordered, immutable sequences). Example: `my_tuple = (1, 2, 3)` 14 | 15 | 3. **Mapping Type:** 16 | - **dict**: Represents dictionaries (key-value pairs). Example: `my_dict = {'name': 'John', 'age': 30}` 17 | 18 | 4. **Set Types:** 19 | - **set**: Represents sets (unordered collections of unique elements). Example: `my_set = {1, 2, 3}` 20 | - **frozenset**: Represents immutable sets. Example: `my_frozenset = frozenset([1, 2, 3])` 21 | 22 | 5. **Boolean Type:** 23 | - **bool**: Represents Boolean values (`True` or `False`). Example: `is_valid = True` 24 | 25 | 6. **Binary Types:** 26 | - **bytes**: Represents immutable sequences of bytes. Example: `data = b'Hello'` 27 | - **bytearray**: Represents mutable sequences of bytes. Example: `data = bytearray(b'Hello')` 28 | 29 | 7. **None Type:** 30 | - **NoneType**: Represents the `None` object, which is used to indicate the absence of a value or a null value. 31 | 32 | 8. **Custom Data Types:** 33 | - You can also define your custom data types using classes and objects. 34 | -------------------------------------------------------------------------------- /Day-02/02-strings.md: -------------------------------------------------------------------------------- 1 | # Strings 2 | 3 | **1. String Data Type in Python:** 4 | 5 | - In Python, a string is a sequence of characters, enclosed within single (' '), double (" "), or triple (''' ''' or """ """) quotes. 6 | - Strings are immutable, meaning you cannot change the characters within a string directly. Instead, you create new strings. 7 | - You can access individual characters in a string using indexing, e.g., `my_string[0]` will give you the first character. 8 | - Strings support various built-in methods, such as `len()`, `upper()`, `lower()`, `strip()`, `replace()`, and more, for manipulation. 9 | 10 | **2. String Manipulation and Formatting:** 11 | 12 | - Concatenation: You can combine strings using the `+` operator. 13 | - Substrings: Use slicing to extract portions of a string, e.g., `my_string[2:5]` will extract characters from the 2nd to the 4th position. 14 | - String interpolation: Python supports various ways to format strings, including f-strings (f"...{variable}..."), %-formatting ("%s %d" % ("string", 42)), and `str.format()`. 15 | - Escape sequences: Special characters like newline (\n), tab (\t), and others are represented using escape sequences. 16 | - String methods: Python provides many built-in methods for string manipulation, such as `split()`, `join()`, and `startswith()`. -------------------------------------------------------------------------------- /Day-02/03-numeric.md: -------------------------------------------------------------------------------- 1 | # Numberic Data Type 2 | 3 | **1. Numeric Data Types in Python (int, float):** 4 | 5 | - Python supports two primary numeric data types: `int` for integers and `float` for floating-point numbers. 6 | - Integers are whole numbers, and floats can represent both whole and fractional numbers. 7 | - You can perform arithmetic operations on these types, including addition, subtraction, multiplication, division, and more. 8 | - Be aware of potential issues with floating-point precision, which can lead to small inaccuracies in calculations. 9 | - Python also provides built-in functions for mathematical operations, such as `abs()`, `round()`, and `math` module for advanced functions. 10 | -------------------------------------------------------------------------------- /Day-02/04-regex.md: -------------------------------------------------------------------------------- 1 | # Regex 2 | 3 | **1. Regular Expressions for Text Processing:** 4 | 5 | - Regular expressions (regex or regexp) are a powerful tool for pattern matching and text processing. 6 | - The `re` module in Python is used for working with regular expressions. 7 | - Common metacharacters: `.` (any character), `*` (zero or more), `+` (one or more), `?` (zero or one), `[]` (character class), `|` (OR), `^` (start of a line), `$` (end of a line), etc. 8 | - Examples of regex usage: matching emails, phone numbers, or extracting data from text. 9 | - `re` module functions include `re.match()`, `re.search()`, `re.findall()`, and `re.sub()` for pattern matching and replacement. -------------------------------------------------------------------------------- /Day-02/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-02/README.md -------------------------------------------------------------------------------- /Day-02/examples/01-string-concat.py: -------------------------------------------------------------------------------- 1 | str1 = "Hello" 2 | str2 = "World" 3 | result = str1 + " " + str2 4 | print(result) 5 | -------------------------------------------------------------------------------- /Day-02/examples/01-string-len.py: -------------------------------------------------------------------------------- 1 | text = "Python is awesome" 2 | length = len(text) 3 | print("Length of the string:", length) 4 | -------------------------------------------------------------------------------- /Day-02/examples/01-string-lowercase.py: -------------------------------------------------------------------------------- 1 | text = "Python is awesome" 2 | uppercase = text.upper() 3 | lowercase = text.lower() 4 | print("Uppercase:", uppercase) 5 | print("Lowercase:", lowercase) 6 | -------------------------------------------------------------------------------- /Day-02/examples/01-string-replace.py: -------------------------------------------------------------------------------- 1 | text = "Python is awesome" 2 | new_text = text.replace("awesome", "great") 3 | print("Modified text:", new_text) 4 | -------------------------------------------------------------------------------- /Day-02/examples/01-string-split.py: -------------------------------------------------------------------------------- 1 | text = "Python is awesome" 2 | words = text.split() 3 | print("Words:", words) 4 | -------------------------------------------------------------------------------- /Day-02/examples/01-string-strip.py: -------------------------------------------------------------------------------- 1 | text = " Some spaces around " 2 | stripped_text = text.strip() 3 | print("Stripped text:", stripped_text) 4 | -------------------------------------------------------------------------------- /Day-02/examples/01-string-substring.py: -------------------------------------------------------------------------------- 1 | text = "Python is awesome" 2 | substring = "is" 3 | if substring in text: 4 | print(substring, "found in the text") 5 | -------------------------------------------------------------------------------- /Day-02/examples/02-float.py: -------------------------------------------------------------------------------- 1 | # Float variables 2 | num1 = 5.0 3 | num2 = 2.5 4 | 5 | # Basic Arithmetic 6 | result1 = num1 + num2 7 | print("Addition:", result1) 8 | 9 | result2 = num1 - num2 10 | print("Subtraction:", result2) 11 | 12 | result3 = num1 * num2 13 | print("Multiplication:", result3) 14 | 15 | result4 = num1 / num2 16 | print("Division:", result4) 17 | 18 | # Rounding 19 | result5 = round(3.14159265359, 2) # Rounds to 2 decimal places 20 | print("Rounded:", result5) 21 | -------------------------------------------------------------------------------- /Day-02/examples/02-int.py: -------------------------------------------------------------------------------- 1 | # Integer variables 2 | num1 = 10 3 | num2 = 5 4 | 5 | # Integer Division 6 | result1 = num1 // num2 7 | print("Integer Division:", result1) 8 | 9 | # Modulus (Remainder) 10 | result2 = num1 % num2 11 | print("Modulus (Remainder):", result2) 12 | 13 | # Absolute Value 14 | result3 = abs(-7) 15 | print("Absolute Value:", result3) 16 | -------------------------------------------------------------------------------- /Day-02/examples/03-regex-findall.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "The quick brown fox" 4 | pattern = r"brown" 5 | 6 | search = re.search(pattern, text) 7 | if search: 8 | print("Pattern found:", search.group()) 9 | else: 10 | print("Pattern not found") 11 | -------------------------------------------------------------------------------- /Day-02/examples/03-regex-match.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "The quick brown fox" 4 | pattern = r"quick" 5 | 6 | match = re.match(pattern, text) 7 | if match: 8 | print("Match found:", match.group()) 9 | else: 10 | print("No match") 11 | -------------------------------------------------------------------------------- /Day-02/examples/03-regex-replace.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "The quick brown fox jumps over the lazy brown dog" 4 | pattern = r"brown" 5 | 6 | replacement = "red" 7 | 8 | new_text = re.sub(pattern, replacement, text) 9 | print("Modified text:", new_text) 10 | -------------------------------------------------------------------------------- /Day-02/examples/03-regex-search.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "The quick brown fox" 4 | pattern = r"brown" 5 | 6 | search = re.search(pattern, text) 7 | if search: 8 | print("Pattern found:", search.group()) 9 | else: 10 | print("Pattern not found") 11 | -------------------------------------------------------------------------------- /Day-02/examples/03-regex-split.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "apple,banana,orange,grape" 4 | pattern = r"," 5 | 6 | split_result = re.split(pattern, text) 7 | print("Split result:", split_result) 8 | -------------------------------------------------------------------------------- /Day-02/strings.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-02/strings.py -------------------------------------------------------------------------------- /Day-03/README.md: -------------------------------------------------------------------------------- 1 | # Keywords and Variables -------------------------------------------------------------------------------- /Day-03/keywords.md: -------------------------------------------------------------------------------- 1 | # Keywords in Python: 2 | 3 | Keywords are reserved words in Python that have predefined meanings and cannot be used as variable names or identifiers. These words are used to define the structure and logic of the program. They are an integral part of the Python language and are case-sensitive, which means you must use them exactly as specified. 4 | 5 | Here are some important Python keywords: 6 | 7 | 1. **and**: It is a logical operator that returns `True` if both operands are true. 8 | 9 | 2. **or**: It is a logical operator that returns `True` if at least one of the operands is true. 10 | 11 | 3. **not**: It is a logical operator that returns the opposite of the operand's truth value. 12 | 13 | 4. **if**: It is used to start a conditional statement and is followed by a condition that determines whether the code block is executed. 14 | 15 | 5. **else**: It is used in conjunction with `if` to define an alternative code block to execute when the `if` condition is `False`. 16 | 17 | 6. **elif**: Short for "else if," it is used to check additional conditions after an `if` statement and is used in combination with `if` and `else`. 18 | 19 | 7. **while**: It is used to create a loop that repeatedly executes a block of code as long as a specified condition is true. 20 | 21 | 8. **for**: It is used to create a loop that iterates over a sequence (such as a list, tuple, or string) and executes a block of code for each item in the sequence. 22 | 23 | 9. **in**: Used with `for`, it checks if a value is present in a sequence. 24 | 25 | 10. **try**: It is the beginning of a block of code that is subject to exception handling. It is followed by `except` to catch and handle exceptions. 26 | 27 | 11. **except**: Used with `try`, it defines a block of code to execute when an exception is raised in the corresponding `try` block. 28 | 29 | 12. **finally**: Used with `try`, it defines a block of code that is always executed, whether an exception is raised or not. 30 | 31 | 13. **def**: It is used to define a function in Python. 32 | 33 | 14. **return**: It is used within a function to specify the value that the function should return. 34 | 35 | 15. **class**: It is used to define a class, which is a blueprint for creating objects in object-oriented programming. 36 | 37 | 16. **import**: It is used to import modules or libraries to access their functions, classes, or variables. 38 | 39 | 17. **from**: Used with `import` to specify which specific components from a module should be imported. 40 | 41 | 18. **as**: Used with `import` to create an alias for a module, making it easier to reference in the code. 42 | 43 | 19. **True**: It represents a boolean value for "true." 44 | 45 | 20. **False**: It represents a boolean value for "false." 46 | 47 | 21. **None**: It represents a special null value or absence of value. 48 | 49 | 22. **is**: It is used for identity comparison, checking if two variables refer to the same object in memory. 50 | 51 | 23. **lambda**: It is used to create small, anonymous functions (lambda functions). 52 | 53 | 24. **with**: It is used for context management, ensuring that certain operations are performed before and after a block of code. 54 | 55 | 25. **global**: It is used to declare a global variable within a function's scope. 56 | 57 | 26. **nonlocal**: It is used to declare a variable as nonlocal, which allows modifying a variable in an enclosing (but non-global) scope. -------------------------------------------------------------------------------- /Day-03/variables.md: -------------------------------------------------------------------------------- 1 | # Understanding Variables in Python: 2 | 3 | In Python, a variable is a named storage location used to store data. Variables are essential for programming as they allow us to work with data, manipulate it, and make our code more flexible and reusable. 4 | 5 | #### Example: 6 | 7 | ```python 8 | # Assigning a value to a variable 9 | my_variable = 42 10 | 11 | # Accessing the value of a variable 12 | print(my_variable) # Output: 42 13 | ``` 14 | 15 | ### Variable Scope and Lifetime: 16 | 17 | **Variable Scope:** In Python, variables have different scopes, which determine where in the code the variable can be accessed. There are mainly two types of variable scopes: 18 | 19 | 1. **Local Scope:** Variables defined within a function have local scope and are only accessible inside that function. 20 | 21 | ```python 22 | def my_function(): 23 | x = 10 # Local variable 24 | print(x) 25 | 26 | my_function() 27 | print(x) # This will raise an error since 'x' is not defined outside the function. 28 | ``` 29 | 30 | 2. **Global Scope:** Variables defined outside of any function have global scope and can be accessed throughout the entire code. 31 | 32 | ```python 33 | y = 20 # Global variable 34 | 35 | def another_function(): 36 | print(y) # This will access the global variable 'y' 37 | 38 | another_function() 39 | print(y) # This will print 20 40 | ``` 41 | 42 | **Variable Lifetime:** The lifetime of a variable is determined by when it is created and when it is destroyed or goes out of scope. Local variables exist only while the function is being executed, while global variables exist for the entire duration of the program. 43 | 44 | ### Variable Naming Conventions and Best Practices: 45 | 46 | It's important to follow naming conventions and best practices for variables to write clean and maintainable code: 47 | 48 | - Variable names should be descriptive and indicate their purpose. 49 | - Use lowercase letters and separate words with underscores (snake_case) for variable names. 50 | - Avoid using reserved words (keywords) for variable names. 51 | - Choose meaningful names for variables. 52 | 53 | #### Example: 54 | 55 | ```python 56 | # Good variable naming 57 | user_name = "John" 58 | total_items = 42 59 | 60 | # Avoid using reserved words 61 | class = "Python" # Not recommended 62 | 63 | # Use meaningful names 64 | a = 10 # Less clear 65 | num_of_students = 10 # More descriptive 66 | ``` 67 | 68 | ### Practice Exercises and Examples: 69 | 70 | #### Example: Using Variables to Store and Manipulate Configuration Data in a DevOps Context 71 | 72 | In a DevOps context, you often need to manage configuration data for various services or environments. Variables are essential for this purpose. Let's consider a scenario where we need to store and manipulate configuration data for a web server. 73 | 74 | ```python 75 | # Define configuration variables for a web server 76 | server_name = "my_server" 77 | port = 80 78 | is_https_enabled = True 79 | max_connections = 1000 80 | 81 | # Print the configuration 82 | print(f"Server Name: {server_name}") 83 | print(f"Port: {port}") 84 | print(f"HTTPS Enabled: {is_https_enabled}") 85 | print(f"Max Connections: {max_connections}") 86 | 87 | # Update configuration values 88 | port = 443 89 | is_https_enabled = False 90 | 91 | # Print the updated configuration 92 | print(f"Updated Port: {port}") 93 | print(f"Updated HTTPS Enabled: {is_https_enabled}") 94 | ``` 95 | 96 | In this example, we use variables to store and manipulate configuration data for a web server. This allows us to easily update and manage the server's configuration in a DevOps context. -------------------------------------------------------------------------------- /Day-04/README.md: -------------------------------------------------------------------------------- 1 | # Python Functions, Modules and Packages 2 | 3 | ## 1. Differences Between Functions, Modules, and Packages 4 | 5 | ### Functions 6 | 7 | A function in Python is a block of code that performs a specific task. Functions are defined using the `def` keyword and can take inputs, called arguments. They are a way to encapsulate and reuse code. 8 | 9 | **Example:** 10 | 11 | ```python 12 | def greet(name): 13 | return f"Hello, {name}!" 14 | 15 | message = greet("Alice") 16 | print(message) 17 | ``` 18 | 19 | In this example, `greet` is a function that takes a `name` argument and returns a greeting message. 20 | 21 | ### Modules 22 | 23 | A module is a Python script containing Python code. It can define functions, classes, and variables that can be used in other Python scripts. Modules help organize and modularize your code, making it more maintainable. 24 | 25 | **Example:** 26 | 27 | Suppose you have a Python file named `my_module.py`: 28 | 29 | ```python 30 | # my_module.py 31 | def square(x): 32 | return x ** 2 33 | 34 | pi = 3.14159265 35 | ``` 36 | 37 | You can use this module in another script: 38 | 39 | ```python 40 | import my_module 41 | 42 | result = my_module.square(5) 43 | print(result) 44 | print(my_module.pi) 45 | ``` 46 | 47 | In this case, `my_module` is a Python module containing the `square` function and a variable `pi`. 48 | 49 | ### Packages 50 | 51 | A package is a collection of modules organized in directories. Packages help you organize related modules into a hierarchy. They contain a special file named `__init__.py`, which indicates that the directory should be treated as a package. 52 | 53 | **Example:** 54 | 55 | Suppose you have a package structure as follows: 56 | 57 | ``` 58 | my_package/ 59 | __init__.py 60 | module1.py 61 | module2.py 62 | ``` 63 | 64 | You can use modules from this package as follows: 65 | 66 | ```python 67 | from my_package import module1 68 | 69 | result = module1.function_from_module1() 70 | ``` 71 | 72 | In this example, `my_package` is a Python package containing modules `module1` and `module2`. 73 | 74 | ## 2. How to Import a Package 75 | 76 | Importing a package or module in Python is done using the `import` statement. You can import the entire package, specific modules, or individual functions/variables from a module. 77 | 78 | **Example:** 79 | 80 | ```python 81 | # Import the entire module 82 | import math 83 | 84 | # Use functions/variables from the module 85 | result = math.sqrt(16) 86 | print(result) 87 | 88 | # Import specific function/variable from a module 89 | from math import pi 90 | print(pi) 91 | ``` 92 | 93 | In this example, we import the `math` module and then use functions and variables from it. You can also import specific elements from modules using the `from module import element` syntax. 94 | 95 | ## 3. Python Workspaces 96 | 97 | Python workspaces refer to the environment in which you develop and run your Python code. They include the Python interpreter, installed libraries, and the current working directory. Understanding workspaces is essential for managing dependencies and code organization. 98 | 99 | Python workspaces can be local or virtual environments. A local environment is the system-wide Python installation, while a virtual environment is an isolated environment for a specific project. You can create virtual environments using tools like `virtualenv` or `venv`. 100 | 101 | **Example:** 102 | 103 | ```bash 104 | # Create a virtual environment 105 | python -m venv myenv 106 | 107 | # Activate the virtual environment (on Windows) 108 | myenv\Scripts\activate 109 | 110 | # Activate the virtual environment (on macOS/Linux) 111 | source myenv/bin/activate 112 | ``` 113 | 114 | Once activated, you work in an isolated workspace with its Python interpreter and library dependencies. -------------------------------------------------------------------------------- /Day-05/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-05/README.md -------------------------------------------------------------------------------- /Day-06/01-Notes/Arithmetic Operators.md: -------------------------------------------------------------------------------- 1 | # Arithmetic Operations in Python 2 | 3 | ## Introduction 4 | 5 | Arithmetic operators in Python allow you to perform basic mathematical calculations on numeric values. These operators include addition, subtraction, multiplication, division, and more. 6 | 7 | ## List of Arithmetic Operators 8 | 9 | 1. **Addition (+):** Adds two numbers. 10 | 2. **Subtraction (-):** Subtracts the right operand from the left operand. 11 | 3. **Multiplication (*):** Multiplies two numbers. 12 | 4. **Division (/):** Divides the left operand by the right operand (results in a floating-point number). 13 | 5. **Floor Division (//):** Divides the left operand by the right operand and rounds down to the nearest whole number. 14 | 6. **Modulus (%):** Returns the remainder of the division of the left operand by the right operand. 15 | 7. **Exponentiation (**):** Raises the left operand to the power of the right operand. 16 | 17 | ## Examples 18 | 19 | ### Addition 20 | 21 | ```python 22 | a = 5 23 | b = 3 24 | result = a + b 25 | print(result) # Output: 8 26 | ``` 27 | 28 | ### Subtraction 29 | 30 | ```python 31 | x = 10 32 | y = 7 33 | result = x - y 34 | print(result) # Output: 3 35 | ``` -------------------------------------------------------------------------------- /Day-06/01-Notes/Assignment Operators.md: -------------------------------------------------------------------------------- 1 | # Assignment Operations in Python 2 | 3 | ## Introduction 4 | 5 | Assignment operators in Python are used to assign values to variables. They include the basic assignment operator (=) and various compound assignment operators that perform an operation on the variable while assigning a value. 6 | 7 | ## List of Assignment Operators 8 | 9 | 1. **Basic Assignment (=):** Assigns a value to a variable. 10 | 11 | 2. **Addition Assignment (+=):** Adds the right operand to the left operand and assigns the result to the left operand. 12 | 13 | 3. **Subtraction Assignment (-=):** Subtracts the right operand from the left operand and assigns the result to the left operand. 14 | 15 | 4. **Multiplication Assignment (*=):** Multiplies the left operand by the right operand and assigns the result to the left operand. 16 | 17 | 5. **Division Assignment (/=):** Divides the left operand by the right operand and assigns the result to the left operand. 18 | 19 | 6. **Floor Division Assignment (//=):** Performs floor division on the left operand and assigns the result to the left operand. 20 | 21 | 7. **Modulus Assignment (%=):** Calculates the modulus of the left operand and assigns the result to the left operand. 22 | 23 | 8. **Exponentiation Assignment (**=):** Raises the left operand to the power of the right operand and assigns the result to the left operand. 24 | 25 | ## Examples 26 | 27 | ### Basic Assignment 28 | 29 | ```python 30 | x = 5 31 | ``` 32 | 33 | ### Addition Assignment 34 | 35 | ```python 36 | y = 10 37 | y += 3 # Equivalent to y = y + 3 38 | ``` -------------------------------------------------------------------------------- /Day-06/01-Notes/Bitwise Operators.md: -------------------------------------------------------------------------------- 1 | # Bitwise Operations in Python 2 | 3 | ## Introduction 4 | 5 | Bitwise operators in Python are used to perform operations on individual bits of binary numbers. These operators include bitwise AND, OR, XOR, and more. 6 | 7 | ## List of Bitwise Operators 8 | 9 | 1. **Bitwise AND (&):** Performs a bitwise AND operation on the binary representations of the operands. 10 | 2. **Bitwise OR (|):** Performs a bitwise OR operation. 11 | 3. **Bitwise XOR (^):** Performs a bitwise XOR operation. 12 | 4. **Bitwise NOT (~):** Flips the bits of the operand, changing 0 to 1 and 1 to 0. 13 | 5. **Left Shift (<<):** Shifts the bits to the left by a specified number of positions. 14 | 6. **Right Shift (>>):** Shifts the bits to the right. 15 | 16 | ## Examples 17 | 18 | ### Bitwise AND 19 | 20 | ```python 21 | a = 5 # Binary: 0101 22 | b = 3 # Binary: 0011 23 | result = a & b # Result: 0001 (Decimal: 1) 24 | ``` 25 | 26 | ### Bitwise OR 27 | 28 | ```python 29 | x = 10 # Binary: 1010 30 | y = 7 # Binary: 0111 31 | result = x | y # Result: 1111 (Decimal: 15) 32 | ``` -------------------------------------------------------------------------------- /Day-06/01-Notes/Identity Operators.md: -------------------------------------------------------------------------------- 1 | # Identity Operations in Python 2 | 3 | ## Introduction 4 | 5 | Identity operators in Python are used to compare the memory locations of two objects to determine if they are the same object or not. The two identity operators are "is" and "is not." 6 | 7 | ## List of Identity Operators 8 | 9 | 1. **is:** Returns `True` if both operands refer to the same object. 10 | 2. **is not:** Returns `True` if both operands refer to different objects. 11 | 12 | ### Examples 13 | 14 | #### is Operator 15 | 16 | ```python 17 | x = [1, 2, 3] 18 | y = x # y now refers to the same object as x 19 | result = x is y 20 | # result will be True 21 | ``` 22 | 23 | #### is not Operator 24 | 25 | ```python 26 | a = "hello" 27 | b = "world" 28 | result = a is not b 29 | # result will be True 30 | ``` -------------------------------------------------------------------------------- /Day-06/01-Notes/Logical Operators.md: -------------------------------------------------------------------------------- 1 | # Logical Operations in Python 2 | 3 | ## Introduction 4 | 5 | Logical operators in Python are used to manipulate and combine Boolean values. These operators allow you to perform logical operations such as AND, OR, and NOT. 6 | 7 | ## List of Logical Operators 8 | 9 | 1. **AND (and):** Returns `True` if both operands are `True`. 10 | 2. **OR (or):** Returns `True` if at least one of the operands is `True`. 11 | 3. **NOT (not):** Returns the opposite Boolean value of the operand. 12 | 13 | ## Examples 14 | 15 | ### AND Operator 16 | 17 | ```python 18 | x = True 19 | y = False 20 | result = x and y 21 | # result will be False 22 | ``` 23 | 24 | ### OR Operator 25 | 26 | ```python 27 | a = True 28 | b = False 29 | result = a or b 30 | # result will be True 31 | ``` 32 | -------------------------------------------------------------------------------- /Day-06/01-Notes/Membership Operators.md: -------------------------------------------------------------------------------- 1 | # Membership Operations in Python 2 | 3 | ## Introduction 4 | 5 | Membership operators in Python are used to check whether a value is present in a sequence or collection, such as a list, tuple, or string. The membership operators are "in" and "not in." 6 | 7 | ## List of Membership Operators 8 | 9 | 1. **in:** Returns `True` if the left operand is found in the sequence on the right. 10 | 2. **not in:** Returns `True` if the left operand is not found in the sequence on the right. 11 | 12 | ### Examples 13 | 14 | #### in Operator 15 | 16 | ```python 17 | fruits = ["apple", "banana", "cherry"] 18 | result = "banana" in fruits 19 | # result will be True 20 | ``` 21 | 22 | #### not in Operator 23 | 24 | ```python 25 | colors = ["red", "green", "blue"] 26 | result = "yellow" not in colors 27 | # result will be True 28 | ``` -------------------------------------------------------------------------------- /Day-06/01-Notes/Precedence Operators.md: -------------------------------------------------------------------------------- 1 | # Precedence of Operations in Python 2 | 3 | ## Introduction 4 | 5 | Precedence of operations in Python defines the order in which different types of operators are evaluated in an expression. Operators with higher precedence are evaluated first. 6 | 7 | ## Examples 8 | 9 | ### Arithmetic Precedence 10 | 11 | ```python 12 | result = 5 + 3 * 2 13 | # Multiplication has higher precedence, so result is 11, not 16 14 | ``` -------------------------------------------------------------------------------- /Day-06/01-Notes/Relational Operators.md: -------------------------------------------------------------------------------- 1 | # Relational Operations in Python 2 | 3 | ## Introduction 4 | 5 | Relational operators in Python are used to compare two values and determine the relationship between them. These operators return a Boolean result, which is either `True` or `False`. 6 | 7 | ## List of Relational Operators 8 | 9 | 1. **Equal to (==):** Checks if two values are equal. 10 | 11 | 2. **Not equal to (!=):** Checks if two values are not equal. 12 | 13 | 3. **Greater than (>):** Checks if the left operand is greater than the right operand. 14 | 15 | 4. **Less than (<):** Checks if the left operand is less than the right operand. 16 | 17 | 5. **Greater than or equal to (>=):** Checks if the left operand is greater than or equal to the right operand. 18 | 19 | 6. **Less than or equal to (<=):** Checks if the left operand is less than or equal to the right operand. 20 | 21 | ## Examples 22 | 23 | ### Equal to 24 | 25 | ```python 26 | a = 5 27 | b = 5 28 | result = a == b 29 | # result will be True 30 | ``` 31 | 32 | ### Not equal to 33 | 34 | ```python 35 | x = 10 36 | y = 7 37 | result = x != y 38 | # result will be True 39 | ``` -------------------------------------------------------------------------------- /Day-06/02-Assignment/01-Questions/assignment.md: -------------------------------------------------------------------------------- 1 | 2 | # Python Operators Assignment 3 | 4 | In this assignment, you will explore various Python operators and their usage. Please complete the following tasks. 5 | 6 | ## Task 1: Arithmetic Operators 7 | 8 | 1. Create two variables `a` and `b` with numeric values. 9 | 2. Calculate the sum, difference, product, and quotient of `a` and `b`. 10 | 3. Print the results. 11 | 12 | ## Task 2: Comparison Operators 13 | 14 | 1. Compare the values of `a` and `b` using the following comparison operators: `<`, `>`, `<=`, `>=`, `==`, and `!=`. 15 | 2. Print the results of each comparison. 16 | 17 | ## Task 3: Logical Operators 18 | 19 | 1. Create two boolean variables, `x` and `y`. 20 | 2. Use logical operators (`and`, `or`, `not`) to perform various logical operations on `x` and `y`. 21 | 3. Print the results. 22 | 23 | ## Task 4: Assignment Operators 24 | 25 | 1. Create a variable `total` and initialize it to 10. 26 | 2. Use assignment operators (`+=`, `-=`, `*=`, `/=`) to update the value of `total`. 27 | 3. Print the final value of `total`. 28 | 29 | ## Task 5: Bitwise Operators (Optional) 30 | 31 | 1. If you are comfortable with bitwise operators, perform some bitwise operations on integer values and print the results. If not, you can skip this task. 32 | 33 | ## Task 6: Identity and Membership Operators 34 | 35 | 1. Create a list `my_list` containing a few elements. 36 | 2. Use identity operators (`is` and `is not`) to check if two variables are the same object. 37 | 3. Use membership operators (`in` and `not in`) to check if an element is present in `my_list`. 38 | 4. Print the results. 39 | 40 | 41 | -------------------------------------------------------------------------------- /Day-06/02-Assignment/02-Answers/task-01-answer.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | b = 5 3 | 4 | sum_result = a + b 5 | difference_result = a - b 6 | product_result = a * b 7 | quotient_result = a / b 8 | 9 | print("Sum:", sum_result) 10 | print("Difference:", difference_result) 11 | print("Product:", product_result) 12 | print("Quotient:", quotient_result) -------------------------------------------------------------------------------- /Day-06/02-Assignment/02-Answers/task-02-answer.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | b = 5 3 | 4 | less_than = a < b 5 | greater_than = a > b 6 | less_than_or_equal = a <= b 7 | greater_than_or_equal = a >= b 8 | equal = a == b 9 | not_equal = a != b 10 | 11 | print("a < b:", less_than) 12 | print("a > b:", greater_than) 13 | print("a <= b:", less_than_or_equal) 14 | print("a >= b:", greater_than_or_equal) 15 | print("a == b:", equal) 16 | print("a != b:", not_equal) 17 | -------------------------------------------------------------------------------- /Day-06/02-Assignment/02-Answers/task-03-answer.py: -------------------------------------------------------------------------------- 1 | x = True 2 | y = False 3 | 4 | and_result = x and y 5 | or_result = x or y 6 | not_result_x = not x 7 | not_result_y = not y 8 | 9 | print("x and y:", and_result) 10 | print("x or y:", or_result) 11 | print("not x:", not_result_x) 12 | print("not y:", not_result_y) 13 | -------------------------------------------------------------------------------- /Day-06/02-Assignment/02-Answers/task-04-answer.py: -------------------------------------------------------------------------------- 1 | total = 10 2 | 3 | total += 5 4 | total -= 3 5 | total *= 2 6 | total /= 4 7 | 8 | print("Final total:", total) 9 | -------------------------------------------------------------------------------- /Day-06/02-Assignment/02-Answers/task-05-answer.py: -------------------------------------------------------------------------------- 1 | my_list = [1, 2, 3, 4, 5] 2 | 3 | # Identity operators 4 | a = my_list 5 | b = [1, 2, 3, 4, 5] 6 | 7 | is_same_object = a is my_list 8 | is_not_same_object = b is not my_list 9 | 10 | # Membership operators 11 | element_in_list = 3 in my_list 12 | element_not_in_list = 6 not in my_list 13 | 14 | print("a is my_list:", is_same_object) 15 | print("b is not my_list:", is_not_same_object) 16 | print("3 in my_list:", element_in_list) 17 | print("6 not in my_list:", element_not_in_list) 18 | -------------------------------------------------------------------------------- /Day-06/README.md: -------------------------------------------------------------------------------- 1 | # Introduction to Operators in Python 2 | 3 | Operators in Python are special symbols or keywords that are used to perform operations on variables and values. Python supports a wide range of operators, categorized into several types. These operators allow you to perform tasks such as arithmetic calculations, assign values to variables, compare values, perform logical operations, and more. 4 | 5 | Here are the main types of operators in Python: 6 | 7 | 1. **Arithmetic Operators:** These operators are used for performing basic mathematical operations such as addition, subtraction, multiplication, division, and more. 8 | 9 | 2. **Assignment Operators:** Assignment operators are used to assign values to variables. They include the equal sign (=) and various compound assignment operators. 10 | 11 | 3. **Relational Operators:** Relational operators are used to compare values and determine the relationship between them. They return a Boolean result (True or False). 12 | 13 | 4. **Logical Operators:** Logical operators are used to combine and manipulate Boolean values. They include "and," "or," and "not." 14 | 15 | 5. **Identity Operators:** Identity operators are used to check if two variables point to the same object in memory. The identity operators in Python are "is" and "is not." 16 | 17 | 6. **Membership Operators:** Membership operators are used to check if a value is present in a sequence or collection, such as a list, tuple, or string. The membership operators in Python are "in" and "not in." 18 | 19 | 7. **Bitwise Operators:** Bitwise operators are used to perform operations on individual bits of binary numbers. They include bitwise AND, OR, XOR, and more. 20 | 21 | 8. **Precedence of Operations:** Operators in Python have different levels of precedence, which determine the order in which operations are performed in an expression. -------------------------------------------------------------------------------- /Day-07/README.md: -------------------------------------------------------------------------------- 1 | # Conditional Statements in Python 2 | 3 | Conditional statements are a fundamental part of programming that allow you to make decisions and execute different blocks of code based on certain conditions. In Python, you can use `if`, `elif` (short for "else if"), and `else` to create conditional statements. 4 | 5 | ## `if` Statement 6 | 7 | The `if` statement is used to execute a block of code if a specified condition is `True`. If the condition is `False`, the code block is skipped. 8 | 9 | ```python 10 | if condition: 11 | # Code to execute if the condition is True 12 | ``` 13 | 14 | - Example: 15 | 16 | ```python 17 | x = 10 18 | if x > 5: 19 | print("x is greater than 5") 20 | ``` 21 | 22 | ## `elif` Statement 23 | 24 | The `elif` statement allows you to check additional conditions if the previous `if` or `elif` conditions are `False`. You can have multiple `elif` statements after the initial `if` statement. 25 | 26 | ```python 27 | if condition1: 28 | # Code to execute if condition1 is True 29 | elif condition2: 30 | # Code to execute if condition2 is True 31 | elif condition3: 32 | # Code to execute if condition3 is True 33 | # ... 34 | else: 35 | # Code to execute if none of the conditions are True 36 | ``` 37 | 38 | - Example: 39 | 40 | ```python 41 | x = 10 42 | if x > 15: 43 | print("x is greater than 15") 44 | elif x > 5: 45 | print("x is greater than 5 but not greater than 15") 46 | else: 47 | print("x is not greater than 5") 48 | ``` 49 | 50 | ## `else` Statement 51 | 52 | The `else` statement is used to specify a block of code to execute when none of the previous conditions (in the `if` and `elif` statements) are `True`. 53 | 54 | ```python 55 | if condition: 56 | # Code to execute if the condition is True 57 | else: 58 | # Code to execute if the condition is False 59 | ``` 60 | 61 | - Example: 62 | 63 | ```python 64 | x = 3 65 | if x > 5: 66 | print("x is greater than 5") 67 | else: 68 | print("x is not greater than 5") 69 | ``` 70 | -------------------------------------------------------------------------------- /Day-08/01-Notes/01-list.md: -------------------------------------------------------------------------------- 1 | # Understanding Lists and List Data Structure 2 | 3 | ## What is a List? 4 | A list is a fundamental data structure in programming that allows you to store a collection of items. Lists are ordered and can contain elements of various data types, such as numbers, strings, and objects. 5 | 6 | ## Creating Lists 7 | You can create a list in various programming languages. In Python, for example, you create a list using square brackets: 8 | ```python 9 | my_list = [1, 2, 3, 'apple', 'banana'] 10 | ``` 11 | 12 | ## List Indexing 13 | List elements are indexed, starting from 0 for the first element. You can access elements by their index. 14 | ```python 15 | first_element = my_list[0] # Access the first element (1) 16 | ``` 17 | 18 | ## List Length 19 | You can find the length of a list using the `len()` function. 20 | ```python 21 | list_length = len(my_list) # Length of the list (5) 22 | ``` 23 | 24 | # List Manipulation and Common List Operations 25 | 26 | ## Appending to a List 27 | You can add elements to the end of a list using the `append()` method. 28 | ```python 29 | my_list.append(4) # Adds 4 to the end of the list 30 | ``` 31 | 32 | ## Removing from a List 33 | You can remove elements by their value using the `remove()` method. 34 | ```python 35 | my_list.remove('apple') # Removes 'apple' from the list 36 | ``` 37 | 38 | ## Slicing a List 39 | Slicing allows you to create a new list from a subset of the original list. 40 | ```python 41 | subset = my_list[1:4] # Creates a new list with elements at index 1, 2, and 3 42 | ``` 43 | 44 | ## Concatenating Lists 45 | You can combine two or more lists to create a new list. 46 | ```python 47 | new_list = my_list + [5, 6] # Concatenates my_list with [5, 6] 48 | ``` 49 | 50 | ## Sorting a List 51 | You can sort a list in ascending or descending order using the `sort()` method. 52 | ```python 53 | my_list.sort() # Sorts the list in ascending order 54 | ``` 55 | 56 | ## Checking for an Element 57 | You can check if an element exists in a list using the `in` keyword. 58 | ```python 59 | is_present = 'banana' in my_list # Checks if 'banana' is in the list (True) 60 | ``` 61 | -------------------------------------------------------------------------------- /Day-08/01-Notes/02-tuple.md: -------------------------------------------------------------------------------- 1 | # Understanding Tuples 2 | 3 | ## What is a Tuple? 4 | A tuple is a data structure similar to a list, but unlike lists, tuples are immutable, meaning their contents cannot be changed after creation. Tuples are typically used for grouping related data. 5 | 6 | ## Creating Tuples 7 | You can create a tuple in various programming languages. In Python, for example, you create a tuple using parentheses: 8 | ```python 9 | my_tuple = (1, 2, 'apple', 'banana') 10 | ``` 11 | 12 | ## Tuple Indexing 13 | Tuple elements are indexed, starting from 0 for the first element. You can access elements by their index, just like lists. 14 | ```python 15 | first_element = my_tuple[0] # Access the first element (1) 16 | ``` 17 | 18 | ## Tuple Length 19 | You can find the length of a tuple using the `len()` function. 20 | ```python 21 | tuple_length = len(my_tuple) # Length of the tuple (4) 22 | ``` 23 | 24 | # Common Tuple Operations 25 | 26 | ## Accessing Tuple Elements 27 | Tuples are immutable, so you can only access their elements. 28 | ```python 29 | second_element = my_tuple[1] # Access the second element (2) 30 | ``` 31 | 32 | ## Tuple Packing and Unpacking 33 | You can pack multiple values into a tuple and unpack them into separate variables. 34 | ```python 35 | coordinates = (3, 4) 36 | x, y = coordinates # Unpack the tuple into x and y (x=3, y=4) 37 | ``` 38 | 39 | ## Concatenating Tuples 40 | You can concatenate two or more tuples to create a new tuple. 41 | ```python 42 | new_tuple = my_tuple + (3.14, 'cherry') # Concatenates my_tuple with a new tuple 43 | ``` 44 | 45 | ## Checking for an Element 46 | You can check if an element exists in a tuple using the `in` keyword. 47 | ```python 48 | is_present = 'apple' in my_tuple # Checks if 'apple' is in the tuple (True) 49 | ``` 50 | 51 | ## Using Tuples for Multiple Return Values 52 | Tuples are often used to return multiple values from a function. 53 | ```python 54 | def get_coordinates(): 55 | return (3, 4) 56 | 57 | x, y = get_coordinates() # Unpack the returned tuple (x=3, y=4) 58 | ``` -------------------------------------------------------------------------------- /Day-08/01-Notes/03-list-vs-tuple.md: -------------------------------------------------------------------------------- 1 | # Differences Between Tuples and Lists 2 | 3 | Tuples and lists are both common data structures used in programming, but they have some fundamental differences that make them suitable for different purposes. Let's explore these differences: 4 | 5 | ## 1. Mutability 6 | 7 | **List:** Lists are mutable, meaning their elements can be added, removed, or modified after creation. You can use methods like `append()`, `remove()`, and `pop()` to change the contents of a list. 8 | 9 | **Tuple:** Tuples are immutable, and once created, their elements cannot be changed, added, or removed. You can't use methods to modify the tuple. 10 | 11 | ## 2. Syntax 12 | 13 | **List:** Lists are created using square brackets `[ ]`. Elements are separated by commas. 14 | 15 | ```python 16 | my_list = [1, 2, 3, 'apple', 'banana'] 17 | ``` 18 | 19 | **Tuple:** Tuples are created using parentheses `( )`. Elements are also separated by commas. 20 | 21 | ```python 22 | my_tuple = (1, 2, 'apple', 'banana') 23 | ``` 24 | 25 | ## 3. Performance 26 | 27 | **List:** Lists may have slightly slower performance compared to tuples because they are mutable. Modifying a list requires memory reallocation, which can be slower for large lists. 28 | 29 | **Tuple:** Tuples have better performance, especially for read-only operations, because of their immutability. They do not require memory reallocation. 30 | 31 | ## 4. Use Cases 32 | 33 | **List:** Lists are used when you need a collection of elements that can change, such as a dynamic list of items or data that needs to be modified. 34 | 35 | **Tuple:** Tuples are used when you need an ordered collection of elements that should not change, such as representing a point in 2D space (x, y), or when you want to ensure the integrity of the data. 36 | 37 | ## 5. Iteration 38 | 39 | **List:** You can use a for loop or other iteration methods to iterate over the elements of a list. 40 | 41 | ```python 42 | for item in my_list: 43 | # Process each item 44 | ``` 45 | 46 | **Tuple:** You can iterate over the elements of a tuple in the same way as lists using a for loop. 47 | 48 | ```python 49 | for item in my_tuple: 50 | # Process each item 51 | ``` 52 | 53 | ## 6. Memory Usage 54 | 55 | **List:** Lists generally consume more memory than tuples because they need to store additional information to support their mutability. 56 | 57 | **Tuple:** Tuples consume less memory because they are immutable, and the interpreter can optimize memory usage. 58 | 59 | -------------------------------------------------------------------------------- /Day-08/01-Notes/04-faq.md: -------------------------------------------------------------------------------- 1 | **Q1: What is a list in Python, and how is it used in DevOps?** 2 | 3 | *Answer:* 4 | A list in Python is a collection of ordered and mutable elements. In DevOps, lists are often used to manage and manipulate data, such as configurations, server names, and deployment targets. For example, you can use a list to store a list of servers that need to be provisioned or configured. 5 | 6 | **Q2: How do you create a list in Python, and can you provide an example related to DevOps?** 7 | 8 | *Answer:* 9 | In Python, you create a list using square brackets `[]`. Here's an example related to DevOps: 10 | 11 | ```python 12 | servers = ['web-server-01', 'db-server-01', 'app-server-01'] 13 | ``` 14 | 15 | This list can be used to represent a list of servers in a DevOps environment. 16 | 17 | **Q3: What is the difference between a list and a tuple in Python, and when would you choose one over the other in a DevOps context?** 18 | 19 | *Answer:* 20 | The key difference is mutability; lists are mutable, while tuples are immutable. In DevOps, if you need a collection of items that won't change (e.g., server configurations, deployment steps), you would use a tuple. If the data can change (e.g., a list of active servers, configuration settings that may be updated), you would use a list. 21 | 22 | **Q4: How can you access elements in a list, and provide a DevOps-related example?** 23 | 24 | *Answer:* 25 | You can access elements in a list by using their index. In a DevOps context, if you have a list of server names and want to access the first server, you would do the following: 26 | 27 | ```python 28 | servers = ['web-server-01', 'db-server-01', 'app-server-01'] 29 | first_server = servers[0] 30 | ``` 31 | 32 | **Q5: How do you add an element to the end of a list in Python? Provide a DevOps example.** 33 | 34 | *Answer:* 35 | You can add an element to the end of a list using the `append()` method. In DevOps, if you want to add a new server to a list of servers, you can do this: 36 | 37 | ```python 38 | servers = ['web-server-01', 'db-server-01'] 39 | servers.append('app-server-01') 40 | ``` 41 | 42 | Now, `servers` will contain 'app-server-01'. 43 | 44 | **Q6: How can you remove an element from a list in Python, and can you provide a DevOps use case?** 45 | 46 | *Answer:* 47 | You can remove an element from a list using the `remove()` method. In a DevOps use case, you might want to remove a server from a list of servers that are no longer needed: 48 | 49 | ```python 50 | servers = ['web-server-01', 'db-server-01', 'app-server-01'] 51 | servers.remove('db-server-01') 52 | ``` -------------------------------------------------------------------------------- /Day-08/02-Assigment/01-list-questions.md: -------------------------------------------------------------------------------- 1 | # Basic-Level List Questions 2 | 3 | **Q1: What is a list in Python, and how is it used in DevOps?** 4 | 5 | **Q2: How do you create a list in Python, and can you provide an example related to DevOps?** 6 | 7 | **Q3: What is the difference between a list and a tuple in Python, and when would you choose one over the other in a DevOps context?** 8 | 9 | **Q4: How can you access elements in a list, and provide a DevOps-related example?** 10 | 11 | **Q5: How do you add an element to the end of a list in Python? Provide a DevOps example.** 12 | 13 | **Q6: How can you remove an element from a list in Python, and can you provide a DevOps use case?** 14 | 15 | -------------------------------------------------------------------------------- /Day-08/02-Assigment/02-list-answers.md: -------------------------------------------------------------------------------- 1 | # Basic-Level List Answers 2 | 3 | **Q1: What is a list in Python, and how is it used in DevOps?** 4 | A list in Python is a collection of ordered and mutable elements. In DevOps, lists are often used to manage and manipulate data, such as configurations, server names, and deployment targets. For example, you can use a list to store a list of servers that need to be provisioned or configured. 5 | 6 | **Q2: How do you create a list in Python, and can you provide an example related to DevOps?** 7 | In Python, you create a list using square brackets `[]`. Here's an example related to DevOps: 8 | ```python 9 | servers = ['web-server-01', 'db-server-01', 'app-server-01'] 10 | ``` 11 | 12 | **Q3: What is the difference between a list and a tuple in Python, and when would you choose one over the other in a DevOps context?** 13 | The key difference is mutability; lists are mutable, while tuples are immutable. In DevOps, if you need a collection of items that won't change (e.g., server configurations, deployment steps), you would use a tuple. If the data can change (e.g., a list of active servers, configuration settings that may be updated), you would use a list. 14 | 15 | **Q4: How can you access elements in a list, and provide a DevOps-related example?** 16 | You can access elements in a list by using their index. In a DevOps context, if you have a list of server names and want to access the first server, you would do the following: 17 | ```python 18 | servers = ['web-server-01', 'db-server-01', 'app-server-01'] 19 | first_server = servers[0] 20 | ``` 21 | 22 | **Q5: How do you add an element to the end of a list in Python? Provide a DevOps example.** 23 | You can add an element to the end of a list using the `append()` method. In DevOps, if you want to add a new server to a list of servers, you can do this: 24 | ```python 25 | servers = ['web-server-01', 'db-server-01'] 26 | servers.append('app-server-01') 27 | ``` 28 | 29 | **Q6: How can you remove an element from a list in Python, and can you provide a DevOps use case?** 30 | You can remove an element from a list using the `remove()` method. In a DevOps use case, you might want to remove a server from a list of servers that are no longer needed: 31 | ```python 32 | servers = ['web-server-01', 'db-server-01', 'app-server-01'] 33 | servers.remove('db-server-01') 34 | ``` -------------------------------------------------------------------------------- /Day-08/README.md: -------------------------------------------------------------------------------- 1 | # Lists and Tuples -------------------------------------------------------------------------------- /Day-09/01-loops.md: -------------------------------------------------------------------------------- 1 | # Loops in Python (for and while) 2 | 3 | ## Introduction 4 | 5 | Loops are a fundamental concept in programming, and they allow you to perform repetitive tasks efficiently. In Python, there are two primary types of loops: "for" and "while." 6 | 7 | ## For Loop 8 | 9 | The "for" loop is used to iterate over a sequence (such as a list, tuple, string, or range) and execute a set of statements for each item in the sequence. The loop continues until all items in the sequence have been processed. 10 | 11 | **Syntax:** 12 | 13 | ```python 14 | for variable in sequence: 15 | # Code to be executed for each item in the sequence 16 | ``` 17 | 18 | **Example:** 19 | 20 | ```python 21 | fruits = ["apple", "banana", "cherry"] 22 | for fruit in fruits: 23 | print(fruit) 24 | ``` 25 | 26 | **Output:** 27 | 28 | ``` 29 | apple 30 | banana 31 | cherry 32 | ``` 33 | 34 | In this example, the loop iterates over the "fruits" list, and in each iteration, the "fruit" variable takes on the value of the current item in the list. 35 | 36 | #### While Loop 37 | 38 | The "while" loop continues to execute a block of code as long as a specified condition is true. It's often used when you don't know in advance how many times the loop should run. 39 | 40 | **Syntax:** 41 | 42 | ```python 43 | while condition: 44 | # Code to be executed as long as the condition is true 45 | ``` 46 | 47 | **Example:** 48 | 49 | ```python 50 | count = 0 51 | while count < 5: 52 | print(count) 53 | count += 1 54 | ``` 55 | 56 | **Output:** 57 | 58 | ``` 59 | 0 60 | 1 61 | 2 62 | 3 63 | 4 64 | ``` 65 | 66 | In this example, the "while" loop continues to execute as long as the "count" is less than 5. The "count" variable is incremented in each iteration. 67 | -------------------------------------------------------------------------------- /Day-09/02-loop-controls.md: -------------------------------------------------------------------------------- 1 | # Loop Control Statements (break and continue) 2 | 3 | ## Introduction 4 | 5 | Loop control statements are used to modify the behavior of loops, providing greater control and flexibility during iteration. In Python, two primary loop control statements are "break" and "continue." 6 | 7 | ## `break` Statement 8 | 9 | The "break" statement is used to exit the loop prematurely. It can be applied to both "for" and "while" loops, allowing you to terminate the loop when a particular condition is met. 10 | 11 | **Example:** 12 | 13 | ```python 14 | numbers = [1, 2, 3, 4, 5] 15 | for number in numbers: 16 | if number == 3: 17 | break 18 | print(number) 19 | ``` 20 | 21 | **Output:** 22 | 23 | ``` 24 | 1 25 | 2 26 | ``` 27 | 28 | In this example, the loop stops when it encounters the number 3. 29 | 30 | ## `continue` Statement 31 | 32 | The "continue" statement is used to skip the current iteration of the loop and proceed to the next one. It can be used in both "for" and "while" loops, enabling you to bypass certain iterations based on a condition. 33 | 34 | **Example:** 35 | 36 | ```python 37 | numbers = [1, 2, 3, 4, 5] 38 | for number in numbers: 39 | if number == 3: 40 | continue 41 | print(number) 42 | ``` 43 | 44 | **Output:** 45 | 46 | ``` 47 | 1 48 | 2 49 | 4 50 | 5 51 | ``` 52 | 53 | In this example, the loop skips the iteration where the number is 3 and continues with the next iteration. 54 | 55 | ## Practice Exercise - Automating Log File Analysis 56 | 57 | #### Introduction 58 | 59 | In this practice exercise, we use a "for" loop to automate the analysis of a log file and identify lines containing the word "error." This demonstrates how loops can be used to process data and extract relevant information efficiently. 60 | 61 | **Example:** 62 | 63 | ```python 64 | log_file = [ 65 | "INFO: Operation successful", 66 | "ERROR: File not found", 67 | "DEBUG: Connection established", 68 | "ERROR: Database connection failed", 69 | ] 70 | 71 | for line in log_file: 72 | if "ERROR" in line: 73 | print(line) 74 | ``` 75 | 76 | **Output:** 77 | 78 | ``` 79 | ERROR: File not found 80 | ERROR: Database connection failed 81 | ``` 82 | 83 | In this exercise, the loop iterates through the "log_file" list and prints lines containing the word "ERROR." -------------------------------------------------------------------------------- /Day-09/03-for-loop-devops-usecases.md: -------------------------------------------------------------------------------- 1 | # For Loop DevOps use-cases 2 | 3 | 1. **Server Provisioning and Configuration:** 4 | 5 | DevOps engineers use "for" loops when provisioning multiple servers or virtual machines with the same configuration. For example, when setting up monitoring agents on multiple servers: 6 | 7 | ```bash 8 | servers=("server1" "server2" "server3") 9 | for server in "${servers[@]}"; do 10 | configure_monitoring_agent "$server" 11 | done 12 | ``` 13 | 14 | 2. **Deploying Configurations to Multiple Environments:** 15 | 16 | When deploying configurations to different environments (e.g., development, staging, production), DevOps engineers can use a "for" loop to apply the same configuration changes to each environment: 17 | 18 | ```bash 19 | environments=("dev" "staging" "prod") 20 | for env in "${environments[@]}"; do 21 | deploy_configuration "$env" 22 | done 23 | ``` 24 | 25 | 3. **Backup and Restore Operations:** 26 | 27 | Automating backup and restore operations is a common use case. DevOps engineers can use "for" loops to create backups for multiple databases or services and later restore them as needed. 28 | 29 | ```bash 30 | databases=("db1" "db2" "db3") 31 | for db in "${databases[@]}"; do 32 | create_backup "$db" 33 | done 34 | ``` 35 | 36 | 4. **Log Rotation and Cleanup:** 37 | 38 | DevOps engineers use "for" loops to manage log files, rotate logs, and clean up older log files to save disk space. 39 | 40 | ```bash 41 | log_files=("app.log" "access.log" "error.log") 42 | for log_file in "${log_files[@]}"; do 43 | rotate_and_cleanup_logs "$log_file" 44 | done 45 | ``` 46 | 47 | 5. **Monitoring and Reporting:** 48 | 49 | In scenarios where you need to gather data or perform checks on multiple systems, a "for" loop is handy. For example, monitoring server resources across multiple machines: 50 | 51 | ```bash 52 | servers=("server1" "server2" "server3") 53 | for server in "${servers[@]}"; do 54 | check_resource_utilization "$server" 55 | done 56 | ``` 57 | 58 | 6. **Managing Cloud Resources:** 59 | 60 | When working with cloud infrastructure, DevOps engineers can use "for" loops to manage resources like virtual machines, databases, and storage across different cloud providers. 61 | 62 | ```bash 63 | instances=("instance1" "instance2" "instance3") 64 | for instance in "${instances[@]}"; do 65 | resize_instance "$instance" 66 | done 67 | ``` 68 | -------------------------------------------------------------------------------- /Day-09/04-while-loop-devops-usecases.md: -------------------------------------------------------------------------------- 1 | # While Loop DevOps Usecases 2 | 3 | DevOps engineers often use "while" loops in various real-time use cases to automate, monitor, and manage infrastructure and deployments. Here are some practical use cases from a DevOps engineer's perspective: 4 | 5 | 1. **Continuous Integration/Continuous Deployment (CI/CD) Pipeline:** 6 | 7 | DevOps engineers often use "while" loops in CI/CD pipelines to monitor the deployment status of applications. They can create a "while" loop that periodically checks the status of a deployment or a rolling update until it completes successfully or fails. For example, waiting for a certain number of pods to be ready in a Kubernetes deployment: 8 | 9 | ```bash 10 | while kubectl get deployment/myapp | grep -q 0/1; do 11 | echo "Waiting for myapp to be ready..." 12 | sleep 10 13 | done 14 | ``` 15 | 16 | 2. **Provisioning and Scaling Cloud Resources:** 17 | 18 | When provisioning or scaling cloud resources, DevOps engineers may use "while" loops to wait for the resources to be fully provisioned and ready. For instance, waiting for an Amazon EC2 instance to become available: 19 | 20 | ```bash 21 | while ! aws ec2 describe-instance-status --instance-ids i-1234567890abcdef0 | grep -q "running"; do 22 | echo "Waiting for the EC2 instance to be running..." 23 | sleep 10 24 | done 25 | ``` 26 | 27 | 3. **Log Analysis and Alerting:** 28 | 29 | DevOps engineers can use "while" loops to continuously monitor logs for specific events or errors and trigger alerts when a certain condition is met. For example, tailing a log file and alerting when an error is detected: 30 | 31 | ```bash 32 | while true; do 33 | if tail -n 1 /var/log/app.log | grep -q "ERROR"; then 34 | send_alert "Error detected in the log." 35 | fi 36 | sleep 5 37 | done 38 | ``` 39 | 40 | 4. **Database Replication and Data Synchronization:** 41 | 42 | DevOps engineers use "while" loops to monitor database replication and ensure data consistency across multiple database instances. The loop can check for replication lag and trigger corrective actions when necessary. 43 | 44 | ```bash 45 | while true; do 46 | replication_lag=$(mysql -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" | awk '{print $2}') 47 | if [ "$replication_lag" -gt 60 ]; then 48 | trigger_data_sync 49 | fi 50 | sleep 60 51 | done 52 | ``` 53 | 54 | 5. **Service Health Monitoring and Auto-Recovery:** 55 | 56 | DevOps engineers can use "while" loops to continuously check the health of services and automatically trigger recovery actions when services become unhealthy. 57 | 58 | ```bash 59 | while true; do 60 | if ! check_service_health; then 61 | restart_service 62 | fi 63 | sleep 30 64 | done 65 | ``` 66 | 67 | -------------------------------------------------------------------------------- /Day-09/README.md: -------------------------------------------------------------------------------- 1 | # Loops -------------------------------------------------------------------------------- /Day-10/01-convert-string-to-list.py: -------------------------------------------------------------------------------- 1 | folder_paths = input("Enter a list of folder paths separated by spaces: ").split() -------------------------------------------------------------------------------- /Day-10/02-main-construct.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | folder_paths = input("Enter a list of folder paths separated by spaces: ").split() 3 | print(folder_paths) 4 | 5 | # Print elements in the list 6 | #for folder_path in folder_paths: 7 | # print(folder_path) 8 | 9 | if __name__ == "__main__": 10 | main() -------------------------------------------------------------------------------- /Day-10/03-list-files-in-folders.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def list_files_in_folder(folder_path): 4 | try: 5 | files = os.listdir(folder_path) 6 | return files, None 7 | except FileNotFoundError: 8 | return None, "Folder not found" 9 | except PermissionError: 10 | return None, "Permission denied" 11 | 12 | def main(): 13 | folder_paths = input("Enter a list of folder paths separated by spaces: ").split() 14 | 15 | for folder_path in folder_paths: 16 | files, error_message = list_files_in_folder(folder_path) 17 | if files: 18 | print(f"Files in {folder_path}:") 19 | for file in files: 20 | print(file) 21 | else: 22 | print(f"Error in {folder_path}: {error_message}") 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /Day-10/README.md: -------------------------------------------------------------------------------- 1 | # Lists Part-2 -------------------------------------------------------------------------------- /Day-11/01-dictionaries.md: -------------------------------------------------------------------------------- 1 | # Dictionaries 2 | 3 | ## Overview: 4 | A dictionary in Python is a data structure that allows you to store and retrieve values using keys. It is also known as a hashmap or associative array in other programming languages. Dictionaries are implemented as hash tables, providing fast access to values based on their keys. 5 | 6 | ## Creating a Dictionary: 7 | ```python 8 | my_dict = {'name': 'John', 'age': 25, 'city': 'New York'} 9 | ``` 10 | 11 | ## Accessing Values: 12 | ```python 13 | print(my_dict['name']) # Output: John 14 | ``` 15 | 16 | ## Modifying and Adding Elements: 17 | ```python 18 | my_dict['age'] = 26 # Modifying a value 19 | my_dict['occupation'] = 'Engineer' # Adding a new key-value pair 20 | ``` 21 | 22 | ## Removing Elements: 23 | ```python 24 | del my_dict['city'] # Removing a key-value pair 25 | ``` 26 | 27 | ## Checking Key Existence: 28 | ```python 29 | if 'age' in my_dict: 30 | print('Age is present in the dictionary') 31 | ``` 32 | 33 | ## Iterating Through Keys and Values: 34 | ```python 35 | for key, value in my_dict.items(): 36 | print(key, value) 37 | ``` -------------------------------------------------------------------------------- /Day-11/02-sets.md: -------------------------------------------------------------------------------- 1 | # Sets and Set Operations 2 | 3 | #### Overview: 4 | A set in Python is an unordered collection of unique elements. It is useful for mathematical operations like union, intersection, and difference. 5 | 6 | #### Creating a Set: 7 | ```python 8 | my_set = {1, 2, 3, 4, 5} 9 | ``` 10 | 11 | #### Adding and Removing Elements: 12 | ```python 13 | my_set.add(6) # Adding an element 14 | my_set.remove(3) # Removing an element 15 | ``` 16 | 17 | #### Set Operations: 18 | ```python 19 | set1 = {1, 2, 3, 4} 20 | set2 = {3, 4, 5, 6} 21 | 22 | union_set = set1.union(set2) # Union of sets 23 | intersection_set = set1.intersection(set2) # Intersection of sets 24 | difference_set = set1.difference(set2) # Difference of sets 25 | ``` 26 | 27 | #### Subset and Superset: 28 | ```python 29 | is_subset = set1.issubset(set2) # Checking if set1 is a subset of set2 30 | is_superset = set1.issuperset(set2) # Checking if set1 is a superset of set2 31 | ``` 32 | 33 | ### Practice Exercises and Examples 34 | 35 | #### Example: Managing a Dictionary of Server Configurations and Optimizing Retrieval 36 | 37 | ##### Scenario: 38 | Suppose you are managing server configurations using a dictionary. 39 | 40 | ```python 41 | server_config = { 42 | 'server1': {'ip': '192.168.1.1', 'port': 8080, 'status': 'active'}, 43 | 'server2': {'ip': '192.168.1.2', 'port': 8000, 'status': 'inactive'}, 44 | 'server3': {'ip': '192.168.1.3', 'port': 9000, 'status': 'active'} 45 | } 46 | ``` 47 | 48 | ##### Function for Retrieval: 49 | ```python 50 | def get_server_status(server_name): 51 | return server_config.get(server_name, {}).get('status', 'Server not found') 52 | ``` 53 | 54 | ##### Example Usage: 55 | ```python 56 | server_name = 'server2' 57 | status = get_server_status(server_name) 58 | print(f"{server_name} status: {status}") 59 | ``` 60 | 61 | -------------------------------------------------------------------------------- /Day-11/03-lists-vs-sets.md: -------------------------------------------------------------------------------- 1 | # Lists vs. Sets 2 | 3 | ## Lists 4 | 5 | - **Ordered Collection:** 6 | - Lists are ordered collections of elements. The order in which elements are added is preserved. 7 | - Elements can be accessed by their index. 8 | 9 | ```python 10 | my_list = [1, 2, 3, 4, 5] 11 | print(my_list[0]) # Output: 1 12 | ``` 13 | 14 | - **Mutable:** 15 | - Lists are mutable, meaning you can modify their elements after creation. 16 | 17 | ```python 18 | my_list[1] = 10 19 | ``` 20 | 21 | - **Allows Duplicate Elements:** 22 | - Lists can contain duplicate elements. 23 | 24 | ```python 25 | my_list = [1, 2, 2, 3, 4] 26 | ``` 27 | 28 | - **Use Cases:** 29 | - Use lists when you need an ordered collection with the ability to modify elements. 30 | 31 | ## Sets 32 | 33 | - **Unordered Collection:** 34 | - Sets are unordered collections of unique elements. The order in which elements are added is not preserved. 35 | - Elements cannot be accessed by their index. 36 | 37 | ```python 38 | my_set = {1, 2, 3, 4, 5} 39 | ``` 40 | 41 | - **Mutable:** 42 | - Sets are mutable, meaning you can add and remove elements after creation. 43 | 44 | ```python 45 | my_set.add(6) 46 | ``` 47 | 48 | - **No Duplicate Elements:** 49 | - Sets do not allow duplicate elements. If you try to add a duplicate, it won't raise an error, but the set won't change. 50 | 51 | ```python 52 | my_set = {1, 2, 2, 3, 4} # Results in {1, 2, 3, 4} 53 | ``` 54 | 55 | - **Use Cases:** 56 | - Use sets when you need an unordered collection of unique elements, and you want to perform set operations like union, intersection, and difference. 57 | 58 | ### Common Operations: 59 | 60 | - **Adding Elements:** 61 | - Lists use `append()` or `insert()` methods. 62 | - Sets use `add()` method. 63 | 64 | - **Removing Elements:** 65 | - Lists use `remove()`, `pop()`, or `del` statement. 66 | - Sets use `remove()` or `discard()` methods. 67 | 68 | - **Checking Membership:** 69 | - Lists use the `in` operator. 70 | - Sets use the `in` operator as well, which is more efficient for sets. 71 | 72 | ```python 73 | # Lists 74 | if 3 in my_list: 75 | print("3 is in the list") 76 | 77 | # Sets 78 | if 3 in my_set: 79 | print("3 is in the set") 80 | ``` 81 | 82 | ### Choosing Between Lists and Sets 83 | 84 | - **Use Lists When:** 85 | - You need to maintain the order of elements. 86 | - Duplicate elements are allowed. 87 | - You need to access elements by index. 88 | 89 | - **Use Sets When:** 90 | - Order doesn't matter. 91 | - You want to ensure unique elements. 92 | - You need to perform set operations like union, intersection, or difference. 93 | -------------------------------------------------------------------------------- /Day-11/04-demo-github-integration.py: -------------------------------------------------------------------------------- 1 | # Program to demonstrate integration with GitHub to fetch the 2 | # details of Users who created Pull requests(Active) on Kubernetes Github repo. 3 | 4 | import requests 5 | 6 | # URL to fetch pull requests from the GitHub API 7 | url = f'https://api.github.com/repos/kubernetes/kubernetes/pulls' 8 | 9 | # Make a GET request to fetch pull requests data from the GitHub API 10 | response = requests.get(url) # Add headers=headers inside get() for authentication 11 | 12 | # Only if the response is successful 13 | if response.status_code == 200: 14 | # Convert the JSON response to a dictionary 15 | pull_requests = response.json() 16 | 17 | # Create an empty dictionary to store PR creators and their counts 18 | pr_creators = {} 19 | 20 | # Iterate through each pull request and extract the creator's name 21 | for pull in pull_requests: 22 | creator = pull['user']['login'] 23 | if creator in pr_creators: 24 | pr_creators[creator] += 1 25 | else: 26 | pr_creators[creator] = 1 27 | 28 | # Display the dictionary of PR creators and their counts 29 | print("PR Creators and Counts:") 30 | for creator, count in pr_creators.items(): 31 | print(f"{creator}: {count} PR(s)") 32 | else: 33 | print(f"Failed to fetch data. Status code: {response.status_code}") 34 | -------------------------------------------------------------------------------- /Day-11/04-practicals.md: -------------------------------------------------------------------------------- 1 | # Practice Exercises and Examples 2 | 3 | ## Example: Managing a Dictionary of Server Configurations and Optimizing Retrieval 4 | 5 | ### Scenario: 6 | Suppose you are managing server configurations using a dictionary. 7 | 8 | ```python 9 | server_config = { 10 | 'server1': {'ip': '192.168.1.1', 'port': 8080, 'status': 'active'}, 11 | 'server2': {'ip': '192.168.1.2', 'port': 8000, 'status': 'inactive'}, 12 | 'server3': {'ip': '192.168.1.3', 'port': 9000, 'status': 'active'} 13 | } 14 | ``` 15 | 16 | ### Function for Retrieval: 17 | ```python 18 | def get_server_status(server_name): 19 | return server_config.get(server_name, {}).get('status', 'Server not found') 20 | ``` 21 | 22 | ### Example Usage: 23 | ```python 24 | server_name = 'server2' 25 | status = get_server_status(server_name) 26 | print(f"{server_name} status: {status}") 27 | ``` 28 | 29 | In this example, the function `get_server_status` optimizes the retrieval of the server status by using the `get` method and providing a default value if the server name is not found. -------------------------------------------------------------------------------- /Day-11/04-practicals.py: -------------------------------------------------------------------------------- 1 | # Server configurations dictionary 2 | server_config = { 3 | 'server1': {'ip': '192.168.1.1', 'port': 8080, 'status': 'active'}, 4 | 'server2': {'ip': '192.168.1.2', 'port': 8000, 'status': 'inactive'}, 5 | 'server3': {'ip': '192.168.1.3', 'port': 9000, 'status': 'active'} 6 | } 7 | 8 | # Retrieving information 9 | def get_server_status(server_name): 10 | return server_config.get(server_name, {}).get('status', 'Server not found') 11 | 12 | # Example usage 13 | server_name = 'server2' 14 | status = get_server_status(server_name) 15 | print(f"{server_name} status: {status}") 16 | -------------------------------------------------------------------------------- /Day-11/README.md: -------------------------------------------------------------------------------- 1 | # Dictionaries and Sets -------------------------------------------------------------------------------- /Day-12/server.conf: -------------------------------------------------------------------------------- 1 | # Server Configuration File 2 | 3 | # Network Settings 4 | PORT = 8080 5 | MAX_CONNECTIONS=600 6 | TIMEOUT = 30 7 | 8 | # Security Settings 9 | SSL_ENABLED = true 10 | SSL_CERT = /path/to/certificate.pem 11 | 12 | # Logging Settings 13 | LOG_LEVEL = INFO 14 | LOG_FILE = /var/log/server.log 15 | 16 | # Other Settings 17 | ENABLE_FEATURE_X = true -------------------------------------------------------------------------------- /Day-12/update_server.py: -------------------------------------------------------------------------------- 1 | def update_server_config(file_path, key, value): 2 | # Read the existing content of the server configuration file 3 | with open(file_path, 'r') as file: 4 | lines = file.readlines() 5 | 6 | # Update the configuration value for the specified key 7 | with open(file_path, 'w') as file: 8 | for line in lines: 9 | # Check if the line starts with the specified key 10 | if key in line: 11 | # Update the line with the new value 12 | file.write(key + "=" + value + "\n") 13 | else: 14 | # Keep the existing line as it is 15 | file.write(line) 16 | 17 | # Path to the server configuration file 18 | server_config_file = 'server.conf' 19 | 20 | # Key and new value for updating the server configuration 21 | key_to_update = 'MAX_CONNECTIONS' 22 | new_value = '600' # New maximum connections allowed 23 | 24 | # Update the server configuration file 25 | update_server_config(server_config_file, key_to_update, new_value) 26 | -------------------------------------------------------------------------------- /Day-13/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-13/README.md -------------------------------------------------------------------------------- /Day-14/README.md: -------------------------------------------------------------------------------- 1 | # Github-JIRA intergration Project -------------------------------------------------------------------------------- /Day-14/examples/create-jira.py: -------------------------------------------------------------------------------- 1 | # This code sample uses the 'requests' library: 2 | # http://docs.python-requests.org 3 | import requests 4 | from requests.auth import HTTPBasicAuth 5 | import json 6 | 7 | url = "https://veeramallaabhishek.atlassian.net/rest/api/3/issue" 8 | 9 | API_TOKEN = "" 10 | 11 | auth = HTTPBasicAuth("", API_TOKEN) 12 | 13 | headers = { 14 | "Accept": "application/json", 15 | "Content-Type": "application/json" 16 | } 17 | 18 | payload = json.dumps( { 19 | "fields": { 20 | "description": { 21 | "content": [ 22 | { 23 | "content": [ 24 | { 25 | "text": "My first jira ticket", 26 | "type": "text" 27 | } 28 | ], 29 | "type": "paragraph" 30 | } 31 | ], 32 | "type": "doc", 33 | "version": 1 34 | }, 35 | "project": { 36 | "key": "AB" 37 | }, 38 | "issuetype": { 39 | "id": "10006" 40 | }, 41 | "summary": "First JIRA Ticket", 42 | }, 43 | "update": {} 44 | } ) 45 | 46 | response = requests.request( 47 | "POST", 48 | url, 49 | data=payload, 50 | headers=headers, 51 | auth=auth 52 | ) 53 | 54 | print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))) -------------------------------------------------------------------------------- /Day-14/examples/list_projects.py: -------------------------------------------------------------------------------- 1 | # This code sample uses the 'requests' library: 2 | # http://docs.python-requests.org 3 | import requests 4 | from requests.auth import HTTPBasicAuth 5 | import json 6 | 7 | url = "https://veeramallaabhishek.atlassian.net/rest/api/3/project" 8 | 9 | API_TOKEN="" 10 | 11 | auth = HTTPBasicAuth("", API_TOKEN) 12 | 13 | headers = { 14 | "Accept": "application/json" 15 | } 16 | 17 | response = requests.request( 18 | "GET", 19 | url, 20 | headers=headers, 21 | auth=auth 22 | ) 23 | 24 | output = json.loads(response.text) 25 | 26 | name = output[0]["name"] 27 | 28 | print(name) -------------------------------------------------------------------------------- /Day-15/README.md: -------------------------------------------------------------------------------- 1 | # Github-JIRA intergration Project - (Part-2) -------------------------------------------------------------------------------- /Day-15/examples/hello-world.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def hello_world(): 7 | return 'Hello, World!' 8 | 9 | if __name__ == '__main__': 10 | app.run("0.0.0.0") 11 | -------------------------------------------------------------------------------- /Day-15/github-jira.py: -------------------------------------------------------------------------------- 1 | # This code sample uses the 'requests' library: 2 | # http://docs.python-requests.org 3 | import requests 4 | from requests.auth import HTTPBasicAuth 5 | import json 6 | from flask import Flask 7 | 8 | app = Flask(__name__) 9 | 10 | # Define a route that handles GET requests 11 | @app.route('/createJira', methods=['POST']) 12 | def createJira(): 13 | 14 | url = "https://veeramallaabhishek.atlassian.net/rest/api/3/issue" 15 | 16 | API_TOKEN="" 17 | 18 | auth = HTTPBasicAuth("", API_TOKEN) 19 | 20 | headers = { 21 | "Accept": "application/json", 22 | "Content-Type": "application/json" 23 | } 24 | 25 | payload = json.dumps( { 26 | "fields": { 27 | "description": { 28 | "content": [ 29 | { 30 | "content": [ 31 | { 32 | "text": "Order entry fails when selecting supplier.", 33 | "type": "text" 34 | } 35 | ], 36 | "type": "paragraph" 37 | } 38 | ], 39 | "type": "doc", 40 | "version": 1 41 | }, 42 | "project": { 43 | "key": "AB" 44 | }, 45 | "issuetype": { 46 | "id": "10006" 47 | }, 48 | "summary": "Main order flow broken", 49 | }, 50 | "update": {} 51 | } ) 52 | 53 | 54 | response = requests.request( 55 | "POST", 56 | url, 57 | data=payload, 58 | headers=headers, 59 | auth=auth 60 | ) 61 | 62 | return json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")) 63 | 64 | if __name__ == '__main__': 65 | app.run(host='0.0.0.0', port=5000) -------------------------------------------------------------------------------- /Day-16/README.md: -------------------------------------------------------------------------------- 1 | # Interview Questions (Beginner and Intermediate) 2 | 3 | ## Describe a real-world example of how you used Python to solve a DevOps challenge. 4 | 5 | - Here you can talk about the projects that we did in this series 6 | - GitHub Webhooks 7 | - JIRA integration 8 | - File Operations 9 | 10 | ## Discuss the challenges that you faced while using Python for DevOps and how did you overcome it. 11 | 12 | - Here you can mention about a challenge that you faced while implementating a Python project for DevOps that we learnt. 13 | 14 | ## How can you secure your Python code and scripts? 15 | 16 | - Handle any sensetive information using Input variables, command line arguments or env vars. 17 | 18 | ## Explain the difference between mutable and immutable objects. 19 | 20 | In Python, mutable objects can be altered after creation, while immutable objects cannot be changed once created. For instance: 21 | 22 | Mutable objects like lists can be modified: 23 | 24 | ``` 25 | my_list = [1, 2, 3] 26 | my_list[0] = 0 # Modifying an element in the list 27 | print(my_list) # Output: [0, 2, 3] 28 | ``` 29 | 30 | Immutable objects like tuples cannot be altered: 31 | 32 | ``` 33 | my_tuple = (1, 2, 3) 34 | # Attempting to change a tuple will result in an error 35 | # my_tuple[0] = 0 36 | ``` 37 | 38 | ## Differentiate between list and tuple in Python. 39 | 40 | Lists are mutable and typically used for storing collections of items that can be changed, while tuples are immutable and commonly used to store collections of items that shouldn't change. Examples: 41 | 42 | List: 43 | 44 | ``` 45 | my_list = [1, 2, 3] 46 | my_list.append(4) # Modifying by adding an element 47 | print(my_list) # Output: [1, 2, 3, 4] 48 | ``` 49 | 50 | Tuple: 51 | 52 | ``` 53 | my_tuple = (1, 2, 3) 54 | # Attempting to modify a tuple will result in an error 55 | # my_tuple.append(4) 56 | ``` 57 | 58 | ## Explain the use of virtualenv. 59 | 60 | Virtualenv creates isolated Python environments, allowing different projects to use different versions of packages without conflicts. Example: 61 | 62 | Creating a virtual environment: 63 | 64 | ### Creating a virtual environment named 'myenv' 65 | virtualenv myenv 66 | 67 | Activating the virtual environment: 68 | 69 | ### On Windows 70 | ``` 71 | myenv\Scripts\activate 72 | ``` 73 | 74 | ### On Unix or MacOS 75 | ``` 76 | source myenv/bin/activate 77 | ``` 78 | 79 | ## What are decorators in Python? 80 | 81 | Decorators modify the behavior of functions. They take a function as an argument, add some functionality, and return another function without modifying the original function's code. Example: 82 | 83 | Defining a simple decorator: 84 | 85 | ``` 86 | def my_decorator(func): 87 | def wrapper(): 88 | print("Something is happening before the function is called.") 89 | func() 90 | print("Something is happening after the function is called.") 91 | return wrapper 92 | 93 | @my_decorator 94 | def say_hello(): 95 | print("Hello!") 96 | 97 | say_hello() 98 | ``` 99 | 100 | ## How does exception handling work in Python? 101 | 102 | Exception handling in Python uses try, except, else, and finally blocks. Example: 103 | 104 | Handling division by zero exception: 105 | 106 | ``` 107 | try: 108 | result = 10 / 0 109 | except ZeroDivisionError: 110 | print("Division by zero is not allowed.") 111 | else: 112 | print("Division successful:", result) 113 | finally: 114 | print("Execution completed.") 115 | ``` 116 | 117 | ## What's the difference between append() and extend() for lists? 118 | 119 | append() adds a single element to the end of a list, while extend() adds multiple elements by appending elements from an iterable. Example: 120 | 121 | Using append(): 122 | ``` 123 | my_list = [1, 2, 3] 124 | my_list.append(4) 125 | print(my_list) # Output: [1, 2, 3, 4] 126 | ``` 127 | 128 | Using extend(): 129 | 130 | ``` 131 | my_list = [1, 2, 3] 132 | my_list.extend([4, 5]) 133 | print(my_list) # Output: [1, 2, 3, 4, 5] 134 | ``` 135 | 136 | ## Explain the use of lambda functions in Python. 137 | 138 | Lambda functions are anonymous functions used for short tasks. Example: 139 | 140 | Defining and using a lambda function: 141 | 142 | ``` 143 | square = lambda x: x**2 144 | print(square(5)) # Output: 25 145 | ``` 146 | 147 | ## What are the different types of loops in Python? 148 | 149 | Python has for loops and while loops. 150 | 151 | Example: 152 | 153 | Using for loop: 154 | ``` 155 | for i in range(5): 156 | print(i) 157 | ``` 158 | 159 | Using while loop: 160 | ``` 161 | i = 0 162 | while i < 5: 163 | print(i) 164 | i += 1 165 | ``` 166 | 167 | ## Explain the difference between == and is operators. 168 | 169 | The == operator compares the values of two objects, while the is operator checks if two variables point to the same object in memory. 170 | 171 | Example: 172 | 173 | Using ==: 174 | 175 | ``` 176 | a = [1, 2, 3] 177 | b = [1, 2, 3] 178 | print(a == b) # Output: True (because values are equal) 179 | ``` 180 | 181 | Using is: 182 | 183 | ``` 184 | a = [1, 2, 3] 185 | b = a 186 | print(a is b) # Output: True (because they reference the same object) 187 | ``` 188 | 189 | ## What is the use of the pass keyword? 190 | 191 | The pass keyword is a no-operation placeholder used when a statement is syntactically needed but no action is required. Example: 192 | 193 | Using pass: 194 | ``` 195 | def placeholder_function(): 196 | pass # To be implemented later 197 | ``` 198 | 199 | ## What is the difference between global and local variables? 200 | 201 | Global variables are defined outside functions and can be accessed anywhere in the code, while local variables are defined inside functions and are only accessible within that function's scope. Example: 202 | 203 | Using a global variable: 204 | ``` 205 | global_var = 10 206 | 207 | def my_function(): 208 | print(global_var) 209 | 210 | my_function() # Output: 10 211 | ``` 212 | 213 | Using a local variable: 214 | 215 | ``` 216 | def my_function(): 217 | local_var = 5 218 | print(local_var) 219 | 220 | my_function() # Output: 5 221 | # Attempting to access local_var outside the function will result in an error 222 | ``` 223 | 224 | ## Explain the difference between open() and with open() statement. 225 | 226 | open() is a built-in function used to open a file and return a file object. 227 | However, it's crucial to manually close the file using file_object.close(). 228 | Conversely, with open() is a context manager that automatically handles file closure, ensuring clean-up even if exceptions occur. 229 | 230 | Example: 231 | ``` 232 | file = open('example.txt', 'r') 233 | content = file.read() 234 | file.close() 235 | ``` 236 | 237 | Using with open(): 238 | ``` 239 | with open('example.txt', 'r') as file: 240 | content = file.read() 241 | # File is automatically closed when the block exits 242 | ``` 243 | 244 | 245 | -------------------------------------------------------------------------------- /Day-17/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-17/README.md -------------------------------------------------------------------------------- /Day-18/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-18/README.md -------------------------------------------------------------------------------- /Day-19/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iam-veeramalla/python-for-devops/14518aeb0a2e08f470f60892bbc83b0b7ba8b5eb/Day-19/README.md -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Abhishek Veeramalla 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Zero to Hero for DevOps Engineers 2 | 3 | Screenshot 2023-10-12 at 9 57 40 PM 4 | 5 | ## Day 1: Introduction to Python, Installation, and Configuration 6 | - Introduction to Python and its role in DevOps. 7 | - Installing Python and setting up a development environment. 8 | - Writing your first Python program. 9 | 10 | ## Day 2: Intro to Datatypes, Working with Strings and Numbers 11 | - String data type in Python. 12 | - String manipulation and formatting. 13 | - Regular expressions for text processing. 14 | - Numeric data types in Python (int, float). 15 | 16 | ## Day 3: Keywords and Variables 17 | - Understanding variables in Python. 18 | - Variable scope and lifetime. 19 | - Variable naming conventions and best practices. 20 | - Practice exercises and examples: 21 | - Example: Using variables to store and manipulate configuration data in a DevOps context. 22 | 23 | ## Day 4: Functions, Modules and Packages 24 | - What are differences between function, modules and packages ? 25 | - How to import a package ? 26 | - What are Python workspaces ? 27 | 28 | ## Day 5: Environment Variables and Command Line Arguments 29 | - Reading and writing environment variables in Python. 30 | - Using the os and dotenv modules. 31 | - Securing sensitive information in environment variables. 32 | - Handling command line arguments in Python. 33 | - Practice exercises and examples: 34 | - Example: Developing a Python script that accepts command line arguments to customize DevOps automation tasks. 35 | 36 | ## Day 6: Operators 37 | - Introduction to operators in Python. 38 | - Arithmetic, comparison, and logical operators. 39 | - Bitwise and assignment operators. 40 | - Practice exercises and examples: 41 | - Example: Using operators to perform calculations and comparisons in a DevOps script. 42 | 43 | ## Day 7: Conditional Handling using if, elif and else 44 | - Conditional statements (if, elif, else). 45 | - Practice exercises and examples: 46 | 47 | ## Day 8: Working with Lists (Part 1) 48 | - Understanding lists and list data structure. 49 | - List manipulation and common list operations. 50 | - Practice exercises and examples: 51 | - Example: Writing a script to manage a list of user accounts in a DevOps environment. 52 | 53 | ## Day 9: Loops 54 | - Loops in Python (for and while). 55 | - Loop control statements (break, continue). 56 | - Practice exercises and examples: 57 | - Example: Automating a log file analysis with a loop to find errors. 58 | 59 | ## Day 10: Working with Lists (Part 2) 60 | - List comprehensions. 61 | - Nested lists and advanced list operations. 62 | - Practice exercises and examples: 63 | - Example: Print list of files in the list of folders provided 64 | 65 | ## Day 11: Working with Dictionaries and Sets (Project-1) 66 | - Dictionaries and key-value pairs. 67 | - Sets and set operations. 68 | - Practice exercises and examples: 69 | - Example: Managing a dictionary of server configurations and optimizing retrieval. 70 | 71 | ## Day 12: Python Tasks for DevOps (Part 1) - File Operations (Project-2) 72 | - Introduction to File Operations and Boto3. 73 | - Automating File operations. 74 | - Practice exercises and examples: 75 | - Example: Update a server resources in the server.conf file up on external notification. 76 | 77 | ## Day 13: Python Tasks for DevOps (Part 2) (Project-3) 78 | - Using Fabric for remote task automation. 79 | - AWS automation with Boto3. 80 | - Managing EC2 instances, S3 buckets, and more. 81 | - Practice exercises and examples: 82 | - Example: Creating a aws script for deploying applications to remote servers. 83 | 84 | ## Day 14: Github-JIRA intergration Project - (Project-4) 85 | - Introduction to RESTful APIs. 86 | - Making HTTP requests using Python. 87 | - Parsing JSON responses and error handling. 88 | - Practice exercises and examples: 89 | - Example: Write a Python API which listens on a github comment and creates a ticket in JIRA. 90 | 91 | ## Day 15: Github-JIRA intergration Project - (Project-4) - (Part-2) 92 | - Introduction to Flask. 93 | - Write your first API in python. 94 | - How to handle API calls and deploy your API to a server. 95 | - Practice exercises and examples: 96 | - Example: Write a Python API which listens on a github comment and creates a ticket in JIRA. 97 | 98 | ## Day 16: Python Interview Questions & Answers 99 | - Beginner and intermediate Level 100 | 101 | ## Day 17: Python Interview Questions & Answers 102 | - Advanced Level 103 | -------------------------------------------------------------------------------- /simple-python-app/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def hello_world(): 7 | return 'Hello, World!' 8 | 9 | if __name__ == '__main__': 10 | app.run(debug=True, host='0.0.0.0', port=8000) -------------------------------------------------------------------------------- /simple-python-app/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.1.0 2 | Werkzeug==2.2.2 --------------------------------------------------------------------------------