0

Understanding Dictionaries

I'm not quite understanding where dict_items is coming from. I don't see a variable for it

1st Mar 2024, 6:18 PM
Nicole Krason
6 Respuestas
+ 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
1st Mar 2024, 6:43 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa thank you
1st Mar 2024, 6:48 PM
Nicole Krason
+ 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.
2nd Mar 2024, 3:57 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa okay, that makes more sense. Thank you
2nd Mar 2024, 4:01 AM
Nicole Krason
1st Mar 2024, 6:18 PM
Nicole Krason
0
Tibor Santa can it be anything you want or does it have to be dict or var?
1st Mar 2024, 8:30 PM
Nicole Krason