# 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:
```python
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:
```python
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
```python
# 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
```python
# 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
```python
# It take all data types.
bio = ('solex', 20, True)
```
To defind a tuple you can also used the tuple() method to do that. example
```python
# Another way of defining a tuple.
friut_names = tuple(('apple', 'mango', 'banana'))
```
#### To access a tuple
```python
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
```python
# 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
```python
# 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
```python
# 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
```python
bio = {
'Name': 'solex',
'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
```python
bio = {
'Name': 'solex',
'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
```python
bio = dict('name'= 'solex', 'age'= 20,)
```
#### To change a dictionary item
```python
# Let change name to something else
bio = {
'Name': 'solex',
'Age': 20,
'IsMarried': False,
'hight': 6.5,
'hight': 2.4
}
bio.update({'Name': solomon})
# Now new value for name is solomon.
```
#### To add an item
```python
# Let add year
bio = {
'Name': 'solex',
'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
```python
# Let remove Name
bio = {
'Name': 'solex',
'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
```python
bio = {
'Name': 'solex',
'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
```python
bio = {
'Name': 'solex',
'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
```python
bio = {
'Name': 'solex',
'Age': 20,
'IsMarried': False,
'hight': 6.5,
'hight': 2.4
bio1 = {
'Name': 'solex',
'Age': 20,
'IsMarried': False,
'hight': 6.5,
'hight': 2.4
}
}
```
To remove every thing in a dictionary you will use the clear() method. example
```python
bio = {
'Name': 'solex',
'Age': 20,
'IsMarried': False,
'hight': 6.5,
'hight': 2.4
}
bio.clear()
```
We learn alot this week at Blockfuse Labs about tuple and Dictionary which we finish on friday with a test and we where given assignment to study about loop and conditionals stay active for my next week update.
# NEVER SETTLE :100: