Let's go learn dictionary.
Let me create a new file.
Name it dictionary dot Pi.
Here I'm going to create a dictionary.
Okay.
And I have to tell you dictionary has keys and value.
And also a dictionary is a collection okay.
Which is unordered, changeable and indexed.
In Python, dictionaries are writing with curly brackets and they have keys and also values.
So let's go and see that.
For example I have um a table of friends.
Okay friends.
And it is equal to we use curly bracket okay.
Here we use for example name.
And then here we use colon.
And for example name is going to be name at and use schema to separate this.
Now this both okay.
Name and these two.
These are one element now okay.
This is the key.
And this part is the value.
And then we have for example last name.
So last name is for example in Richmond.
And we have date of birth okay.
So date of birth is going to be for example 30 or.
Let's use this one okay.
Now I have a dictionary okay.
That contains keys and values.
And now I can print this okay.
So let's print it okay.
Print friends.
And let's see if it is giving me the keys for the values or both.
Okay.
Python.
And as you see right now, it is giving me the names and also sorry the keys and also the values.
Okay.
So how I, how I can get to this.
Okay.
How can I print for example, uh, only the name.
Okay.
How can I do that.
So let's use here.
For example I have a key and name of key is name okay or last name.
So now let's I'm accessing the values using its key.
Now I have friends okay.
It has a key.
Key is name and its value is name.
Okay.
Now let's see if it is giving me or not.
As you see it is giving me a value for name.
Also, if I ask for DOB, which is date of birth.
Again, it is giving me the date of birth.
Okay, so that is how you can print a the one element from a list.
And also we can use loop to go to go through and print keys and also values.
And by using a function called item built in function called items.
Okay.
So let's go and see that.
Let's use for x and y okay.
And friends dot we have a built in function for this.
It is items okay.
Now we have this.
And right here I'm going to print X and y.
So let's save this and execute the program.
As you see we have name which is name.
And last name and date of birth is 1998.
Okay.
So this is how we can print both of them.
And.
Uh, what else I can tell you we can use condition, but you haven't learned anything about condition
yet.
And we will cover those later on.
Okay.
So here you learn how to print, uh, a value using its key and also how to print both of them.
Key and value for uh, using for loop.
And also we can, uh, concatenate some text here for example, I can say here, okay, while printing
I am going to print a text as well.
I will say key is equal to this one okay.
And then concatenate this.
And then right here I can say value and concatenate that one too.
Now it is I am able to concatenate because this one is a string.
And also this one is also a string.
So string with string can be concatenated.
But if some of them could be integer so it's not able to be concatenated.
Okay.
Now you see key is equal to name and value is equal to name.
And what if I change this to integer.
Let's change it to integer.
Now you see there is.
It will give you an error.
And that is here.
You see it is printing.
The first line is printing the second line, but only is coming to the last one.
It is telling you that you can only concatenate string with string, not integer with string.
So how can I do that?
How can I solve this?
As you see, the key itself is a string and the value is integer.
So here I can change it okay.
Using okay I can cast this okay.
I can use it in str function.
And now the problem will be solved is this is one way that we can do.
Or we could change this back to string.
So we don't need to use str right here.
And that is how we can create our dictionary and how we can use it to print the data and a lot of things.
Okay.
So through the course we will be using this a lot.
And you will learn this with a lot of information.
So see you.