here are two different methods that you can use with dictionaries that can really help simplify your life to get started let's create a dictionary so here we'll have let's say some people of type dictionary and that's going to equal let's say Mario will be user 1 and Luigi who will be user too right now if you want to access a value from this dictionary you're going to have to refer to the key and this is basic python 101 so we can print for example the people at the index of Mario and when you run that
you're going to get one as an output to the console so that's pretty normal we all understand how dictionaries work and of course if you type in a key that does not exist python is going to give you a key error because there's no key called ASD so there are two methods you absolutely should know about if you want to grab elements from a dictionary and one is dot get and other one is dot set default let's start with DOT get if you call Dot get you can choose to specify a key such as Mario
and you can also choose to specify a default value so in case Mario doesn't exist we're going to return 0 for example now if we run this we're going to get one as usual Mario is one Mario exists but this time if we type in ASD a key which does not exist we're going to get the default value back which is 0 in this case and if you do not specify a default value it's going to return none by default so in case you want to grab an element without throwing an error you can use
dot get and then you can perform whatever kind of operation you want and combine that with some if statements so dot get is great but what about set default how does this differ from dot get because right now if we type in set default and we say we want Mario otherwise zero we're going to get a similar result for example right now if we try to get Mario it's going to return to us one if we try to return ASD we're going to get 0 back so what is the difference between set default and Dot
get well let me show you one thing so here we're going to put get and we're going to return 0 and then we will print the people and then we will print the people after set default so print people now if we run this you'll notice that the first time we run it with DOT get it won't find ASD so it's going to default to zero and it's going to return to us 0. and the dictionary is going to remain unchanged but for the second example using set default we still try to access ASD which
does not exist so what we do is set a default value for this key which means now we have Mario Luigi and ASD with the default value of zero so set default is going to create that key and set that default value for that key if it does not exist it's actually adding to the dictionary so both of these are pretty powerful dictionary methods which I absolutely recommend you look into because they can really simplify your life when working in Python but anyways do let me know what you think about these methods whether you use
them in your code or not or if you have other methods that you really enjoy using I would love to hear about that in the comment section down below but otherwise as always thanks for watching and I'll see you in the next video