Home » Python

Python Dictionary values() Method with Example

Python Dictionary values() Method: Here, we are going to learn how to get the values of the dictionary as a view object?
Submitted by IncludeHelp, on November 26, 2019

Dictionary values() Method

values() method is used to get all values of a dictionary, it returns a view object that contains the all values of the dictionary as a list.

Syntax:

    dictionary_name.values()

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is <class 'dict_values'>, it returns all values as a view object that contains a list of all values.

Example:

# Python Dictionary values() Method with Example

# dictionary declaration
student = {
  "roll_no": 101,
  "name": "Shivang",
  "course": "B.Tech",
  "perc" : 98.5
}

# printing dictionary
print("data of student dictionary...")
print(student)

# getting all values
x = student.values()
print(x)

# printing type of values() Method
print('Type is: ',type(student.values()))

# changing the value
# it will effect the value of view object also
student['course'] = 'MCA'

# printing dictionary
print("data of student dictionary...")
print(student)

# getting all values
x = student.values()
print(x)

Output

data of student dictionary...
{'roll_no': 101, 'name': 'Shivang', 'course': 'B.Tech', 'perc': 98.5}
dict_values([101, 'Shivang', 'B.Tech', 98.5])
Type is:  <class 'dict_values'>
data of student dictionary...
{'roll_no': 101, 'name': 'Shivang', 'course': 'MCA', 'perc': 98.5}
dict_values([101, 'Shivang', 'MCA', 98.5])






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.