0
Understanding Dictionaries
I'm not quite understanding where dict_items is coming from. I don't see a variable for it
6 Antworten
+ 2
The dictionary is a standard built-in type. It has its own predefined methods. When you create a dictionary and assign it to a variable, you can invoke the dict methods on the variable using the dot notation, like:
var.keys()
var.values()
var.items()
var.get()
And so on.
You can find the complete list of these methods and other features, in the documentation.
https://docs.python.org/3/library/stdtypes.html#typesmapping
+ 1
Tibor Santa thank you
+ 1
{'name': 'Nicole'}
This is a declaration of a dictionary object.
student = {'name': 'Nicole'}
This is assigning the dictionary to a variable called student. From this point, you can refer to this data using the variable name, like:
student.items()
or:
student['name']
It does not matter for Python, what is the name of your variable. As long as it does not clash with a keyword or a built-in function, so you should NOT use 'dict' as variable name.
Picking the best name is important for YOU, the programmer, and whoever else is going to read your code. Good names give a good idea about what is hiding behind the name. They almost document your code on their own.
+ 1
Tibor Santa okay, that makes more sense. Thank you
0
Code for reference: https://sololearn.com/compiler-playground/cM16GcP5rRdr/?ref=app
0
Tibor Santa can it be anything you want or does it have to be dict or var?