WEEK 5 SUMMARY # DATA TYPES, STRINGS, SLICING, SPLIT **Constructor Functions:** In our exploration of data types, we examined constructor functions in Python. These functions allow us to create value types using keywords such as int, float, bool, and str. When a variable's value is enclosed within a constructor function, the type of the value is automatically determined by the constructor, often changing it from one type to another. ``` python # Assigning a name name = "Name" # Using constructor functions to convert data types num1 = int("6") num2 = int("7") num3 = float(8) text1 = str(9) text2 = str(10) # A variable with no value yet empty_var = None # Adding an integer and a float after converting the result to integer first = int("10") second = float(10.9) sum_result = int(first + second) print(sum_result) # Simple arithmetic operations a = 4 b = 5 c = 2 # First calculation total = a * b + c print(total) # Second calculation total = b * c + a print(total) ``` **STRINGS** We explored the string data type and its formatting methods. Strings are sequences of characters, represented by literals or variable values in double quotes like "String" or "123." In Python, strings are stored in an array format, where each character has an index starting from zero and can be accessed by these indices. ```python= company = "Blockfuse Labs" print(company) ``` **SLICING:** In Python, you can obtain a subset of characters from a string through a technique called slicing. This method allows you to extract particular segments of string characters that you desire, producing a new version. Slicing can be performed using both starting and ending indices, which can be included or excluded..Using the start and end(stop) values to slice. You can also slice a string with negative indices, starting from -1 and excluding index 0. ```python= # String slicing examples # From index 2 to 4 (5 not included) print(company[2:5]) # From start to index 4 print(company[:5]) # From index 5 to the end print(company[5:]) ``` .lower(), .upper(), and .capitalize() are string formatting methods that can adjust the appearance or presentation of strings. ![cop](https://hackmd.io/_uploads/ByEPX0W8xx.jpg) **The SPLIT method** indicated as .split (" "), is useful for handling large amounts of string data. Accessing individual characters in such a string can be cumbersome, but the .split(" ") method simplifies this by transforming the string data type into a list data type. This .split(" ") method takes an argument known as a delimiter, which can be either a single character or a sequence that divides elements within a list.. ![cop](https://hackmd.io/_uploads/r1hYVC-Ulg.jpg) We were given tasks to use any of the methods (slicing/spliting); ![cop](https://hackmd.io/_uploads/HkU9BAZUll.jpg) i used slicing/indexing method. **CONCLUSION** We looked at key Python basics like data type conversion (e.g., int(), float(), str()), simple arithmetic operations, and string slicing using start and end indexes. These are just a few of Python’s many tools—especially when working with strings, which are a broad and flexible data type. The code and solutions shared are just one way to approach problems—Python allows for multiple valid methods, so explore and find what works best for you.