Python3 Att Dictionary Values
# Python3.x Python3 Dictionary values() Method
[ Python3 Dictionary](#)
* * *
## Description
The Python3 dictionary `values()` method returns a view object.
[dict.keys()](#), `dict.values()`, and [dict.items()](#) all return view objects, which provide a dynamic view of the dictionary's entries. This means that if the dictionary changes, the view reflects those changes.
View objects are not lists and do not support indexing. You can convert them to a list using `list()`.
We cannot modify the view object in any way because dictionary view objects are read-only.
## Syntax
The syntax for the `values()` method is:
dict.values()
## Parameters
* NA.
## Return Value
Returns a view object.
## Example
The following example demonstrates the usage of the `values()` method:
## Example
>>> dishes ={'eggs': 2,'sausage': 1,'bacon': 1,'spam': 500}
>>> keys = dishes.keys()
>>> values = dishes.values()
>>># Iterate
>>> n =0
>>>for val in values:
... n += val
>>>print(n)
504
>>># keys and values iterate in the same order (insertion order)
>>>list(keys)# Convert to list using list()
['eggs','sausage','bacon','spam']
>>>list(values)
[2,1,1,500]
>>># The view object is dynamic and affected by changes to the dictionary. Deleting keys from the dictionary changes the view object when converted to a list.
>>>del dishes['eggs']
>>>del dishes['sausage']
>>>list(values)
[1,500]
>>># Comparing two dict.values() always returns False
>>> d ={'a': 1}
>>> d.values()== d.values()
False
* * Python3 Dictionary](#)
YouTip