One of the only times you need to use curly brackets in python...
Lets say you wanted to create values for something... lets say a person.
You can make a class, or you can make a dictionary.
here, lets clean this up a bit.
So now, we have a dictionary with the values of the person's smarts, looks, and power.
But how would you call one of these?
person is the dictionary, and
['smarts'] is one of the values of a key, so it will print the value of smarts, which is 74.
If you just print person -
it will give you this:
Lets say you wanted to format the print statement to print everything in a readable way. You would do this:
and the output would be:
value is the name of the key, and
person[value] is the value of that key.
and now... embedded dictionaries!
yes, you can have a dictionary inside of another dictionary.
so to call something inside of an embedded dictionary, you do this:
lets break this down
car_speed: the variable we are assigning this to
things: the dictionary with the value
['cars']: inside of the cars dictionary
['speed']: the value of speed
car_speed would equal 85.
Another cool way you can print the values is like this:
and the output is:
you can have even MORE embedded dictionaries, such as:
Changing the values
so, what if you wanted to change a value inside of a dictionary?
and then, if you type "Hello, world!", the dictionary key
input 1 will be added with the value of
Same as a list, if you do this:
It will also change the value of the original dictionary.
Instead, you need to use
and now, the values will be different.
If you want to only copy a key/value in the dictionary and not the whole thing, do this:
Again, the values will be different.
Note: if the value of the key you want to copy is not
int, change it to it, such as if it is a string, use
str, or if it is a dictionary, use
If you want to delete a key, use
dictionary will have the value of
If you have any questions or want me to explain anything more, I will be glad to.