‎WEEK EIGHT(8) UPDATE OF MY SOFTWARE ENGINEERING JORNEY AT BLOCKFUSE LABS. ‎Python is now taking us deeper and depper. this week was about the python data type call tuple and dictionary. the tuple data type is just like list data type too but the tuple uses the () as it parentasis. As i said in my last update about the list data type it can take all other data type so is the tuple too. it store multiple value or item in a single variable also tuple are orderd or unchangeable. i will show you how a tuple is writen below: ‎ ‎friuts_name = ('apple', 'mango', 'banana') ‎The tuple item are indexed like that of list the first has the index [0] while the second has [1] continuesly… and the items can not be changed but it allow duplicate that is values with the same name. example: ‎ ‎friuts_name = ('apple', 'mango', 'apple', 'mango') ‎If you want to know how many items are in your tuple you will used the len() method example ‎ ‎# To know how many items are in the tuple. ‎friuts_name = ('apple', 'mango', 'banana') ‎print(len(friuts_name) ‎If your tuple is having only one item you need to add a comma by the end to specify the data type if not it is not a tuple. example ‎ ‎# A tuple ‎friut_name = ('mango',) ‎ ‎# Not a tuple ‎friut_name = ('mango') ‎you will notice the difference is the comma after the name of the friut without that comma it means the data type is a string because is in quotation. As i said before it takes in all data types. example ‎ ‎# It take all data types. ‎bio = ('solex', 20, True) ‎To defind a tuple you can also used the tuple() method to do that. example ‎ ‎# Another way of defining a tuple. ‎friut_names = tuple(('apple', 'mango', 'banana')) ‎To access a tuple ‎friuts_name = ('apple', 'mango', 'banana') ‎# To print mango you can used negetive index too and slicing ‎print(friuts_name[1]) ‎To update a tuple ‎To change a tuple item you need to convert it to list first cuz remember tuple is not changeable so you need to covert to list first after we change it then convert back to tuple ‎ ‎To change a value ‎# Let change mango to something else. ‎friuts_name = ('apple', 'mango', 'banana') ‎convert = list(friuts_name) ‎convert[1] = 'painapple' ‎friuts_name = tuple(convert) ‎To add value at the end ‎# Another way ‎# Let add another friut at the end ‎friuts_name = ('apple', 'mango', 'banana') ‎convert = list(friuts_name) ‎convert.append('paenapple') ‎friuts_name = tuple(convert) ‎To remove a value from the tuple ‎# Another way ‎# Let remove apple from the tuple. ‎friuts_name = ('apple', 'mango', 'banana') ‎convert = list(friuts_name) ‎convert.remove('apple') ‎friuts_name = tuple(convert) ‎DICTIONARY ‎Dictionaries are used to store values in key:value pairs and it is changeable but don't allow duplicate. Dictionary is writen in curly bracket and have keys and values. It accept all data types and it does't use indexing it uses the key insted. example ‎ ‎bio = { ‎ 'Name': 'Ben ', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'fav color': ['black', 'red'] ‎} ‎# Now to print only the name we will used the key. ‎print(bio['Name']) ‎Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary has been created. and the can not have two item with the same key. example ‎ ‎bio = { ‎ 'Name': 'Ben', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎# If you print this it will only have one hight and the value will be 2.4 ‎You can also used the dict() method to defind a dictionary. example ‎ ‎bio = dict('name'= 'Ben', 'age'= 20,) ‎To change a dictionary item ‎# Let change name to something else ‎bio = { ‎ 'Name': 'Ben ', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎bio.update({'Name':James}) ‎# Now new value for name is solomon. ‎To add an item ‎# Let add year ‎bio = { ‎ 'Name': 'Ben', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎bio['year'] = 2020 ‎# You can also used the .update() if you like. ‎To remove an item ‎# Let remove Name ‎bio = { ‎ 'Name': 'Benjamin', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎# Three ways to do same thing ‎bio.pop('Name') ‎del bio['Name'] ‎# This popitem remove the last item. ‎bio.popitem() ‎ ‎To copy dictionary ‎bio = { ‎ 'Name': 'Benjamin James ', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎# Two ways ‎bio2 = dict(bio) ‎bio2 = bio.copy ‎# Now we have bio and bio2 with same items but diferent memory location. ‎To have two dictionary with same memory location ‎bio = { ‎ 'Name': 'Ben', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎bio2 = bio ‎# Now we have bio and bio2 with same item same memory location. ‎Nested dictionary ‎Is a dictionary inside a dictionary. example ‎ ‎bio = { ‎ 'Name': 'Ben', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎ bio1 = { ‎ 'Name': 'Ben, ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎ } ‎} ‎To remove every thing in a dictionary you will use the clear() method. example ‎ ‎bio = { ‎ 'Name': 'Ben', ‎ 'Age': 20, ‎ 'IsMarried': False, ‎ 'hight': 6.5, ‎ 'hight': 2.4 ‎} ‎bio.clear() ‎Currently in week 9 now