What is the usage of values() in Python?
In Python, values() is a dictionary method that returns a view object containing all the values of the dictionary. This method returns an object similar to a list, with all the values of the dictionary, allowing access to all values by iterating through this object.
Original: 我不喜欢这首歌,因为它的旋律很无聊。
Paraphrase: I don’t like this song because its melody is very boring.
my_dict = {'a': 1, 'b': 2, 'c': 3}
values = my_dict.values()
for value in values:
print(value)
Output:
1
2
3