Python Dictionary values() Method
The Python dict.values() method returns all values from a dictionary.
It is useful when you want the values only and do not need the keys. A common beginner use case is getting all values from a dictionary so you can print them, loop through them, or convert them to a list.
Quick example #
student = {"name": "Ana", "age": 20, "city": "Lima"}
values = student.values()
print(values)
print(list(values))
Output:
dict_values(['Ana', 20, 'Lima'])
['Ana', 20, 'Lima']
values() returns a dictionary view object. Convert it to a list if you want a regular list.
What values() does #
- It is used on a dictionary
- It returns all dictionary values
- It keeps the same order as the dictionary
- It returns a view object, not a new list
If you already know how to create dictionaries, see creating a dictionary in Python.
Basic syntax #
my_dict.values()
Key points:
values()takes no arguments- It works only on dictionary objects
- You must include the parentheses:
values()
This is a dictionary method, similar to keys() for dictionary keys and items() for key-value pairs.
What values() returns #
values() returns a dict_values object.
This object is a view of the dictionary values. That means it shows the current values in the dictionary, and it updates if the dictionary changes.
Example:
person = {"name": "Mia", "age": 25}
values_view = person.values()
print(values_view)
person["city"] = "Quito"
print(values_view)
Output:
dict_values(['Mia', 25])
dict_values(['Mia', 25, 'Quito'])
If you need a regular list, use list(my_dict.values()).
person = {"name": "Mia", "age": 25}
values_list = list(person.values())
print(values_list)
Output:
['Mia', 25]
Simple example #
Here is a basic example step by step:
car = {"brand": "Toyota", "year": 2022, "color": "blue"}
result = car.values()
print(result)
print(list(result))
Output:
dict_values(['Toyota', 2022, 'blue'])
['Toyota', 2022, 'blue']
What happens here:
caris a dictionarycar.values()gets all valuesprint(result)shows thedict_valuesobjectprint(list(result))shows the same values as a list
Looping through dictionary values #
You can loop through dictionary values with a for loop.
scores = {"math": 90, "english": 85, "science": 88}
for value in scores.values():
print(value)
Output:
90
85
88
This is useful when:
- You only need the values
- You do not care about the keys
- You want simpler code
If you want to loop through keys and values together, see Python dictionary items() method or how to loop through a dictionary in Python.
Converting values to a list #
Use list(my_dict.values()) when you need a list.
fruit_prices = {"apple": 2, "banana": 1, "orange": 3}
price_list = list(fruit_prices.values())
print(price_list)
print(price_list[0])
Output:
[2, 1, 3]
2
This is helpful for:
- Displaying the values as a normal list
- Accessing values by index
- Passing the values to code that expects a list
This matters because dict_values is not the same as a list.
values() vs keys() vs items() #
These three dictionary methods are related, but they return different things:
values()returns only the valueskeys()returns only the keysitems()returns key-value pairs
Examples:
student = {"name": "Ana", "age": 20}
print(student.keys())
print(student.values())
print(student.items())
Output:
dict_keys(['name', 'age'])
dict_values(['Ana', 20])
dict_items([('name', 20)])
Use:
Common beginner mistakes #
Here are some common problems with values().
Calling values() on the wrong type #
values() works on dictionaries only.
Wrong:
my_list = [1, 2, 3]
print(my_list.values())
This causes an error because lists do not have a values() method.
To debug this, check the type:
print(type(my_list))
If you get an AttributeError, see how to fix 'object has no attribute' errors.
Assuming values() returns a list #
Beginners often expect this:
student = {"name": "Ana", "age": 20}
values = student.values()
print(type(values))
Output:
<class 'dict_values'>
It returns dict_values, not a list.
If you need a list:
values = list(student.values())
Trying to use an index directly on dict_values #
This may not work the way you expect:
student = {"name": "Ana", "age": 20}
values = student.values()
# print(values[0]) # Avoid this
Convert to a list first:
student = {"name": "Ana", "age": 20}
values = list(student.values())
print(values[0])
Using values instead of values() #
This is also a common mistake:
student = {"name": "Ana", "age": 20}
print(student.values)
student.values refers to the method itself, not the result.
Use:
print(student.values())
Using parentheses incorrectly on the dictionary variable #
Make sure the method is called on the dictionary:
data = {"a": 1, "b": 2}
print(data.values())
Not like this:
# Wrong examples:
# data().values()
# values(data)
Useful debugging steps:
print(type(my_dict))
print(my_dict)
print(my_dict.values())
print(list(my_dict.values()))
FAQ #
What does dict.values() return in Python? #
It returns a dict_values view object containing the dictionary’s values.
Does values() return a list? #
No. It returns a view object. Use list(...) if you need a list.
Can I loop through dict.values()? #
Yes. It is iterable, so you can use it in a for loop.
Does dict.values() change if the dictionary changes? #
Yes. The returned view reflects updates to the dictionary.
How is values() different from items()? #
values() returns only values. items() returns key-value pairs.