How to Use Dictionary values() Method in PythonPython Basics


The values() method returns a list of all the values in the dictionary.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

dict1 = {'Name': 'Volkswagen', 'Vehicle type': 'SUV','Turbo':'no','Price': 150000,'gearbox': 'automatic-shift'}
print(dict1)
print(dict1.values())
print(list(dict1.values()))

Output:

{'Name': 'Volkswagen', 'Vehicle type': 'SUV', 'Turbo': 'no', 'Price': 150000, 'gearbox': 'automatic-shift'}
dict_values(['Volkswagen', 'SUV', 'no', 150000, 'automatic-shift'])
['Volkswagen', 'SUV', 'no', 150000, 'automatic-shift']

Syntax

dictionary.values()

Parameters

The method doesn’t take any parameters.

Return Value

It returns an iterator.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us