Write a program to print values of dictionary


The program defines a dictionary named "student" which contains information about a student. The information includes the student's name, roll number, marks, age, gender, and city.

  • The first line print(student.values()) retrieves a list of all the values in the dictionary and prints it.
  • The second line print("\n==== Values ====") is just a label to separate the list of values from the rest of the output.
  • The third line for v in student.values(): starts a for loop that iterates over each value in the "student" dictionary. The loop variable "v" takes the value of each value in turn during each iteration.
  • The fourth line print(" ",v) prints the value of "v" which is one of the values in the "student" dictionary.

In summary, the program retrieves all the values from the "student" dictionary and prints each value on a separate line.

Source Code

student = {
	"Name": "Tara",
	"RollNo":130046, 
	"Mark": 458, 
	"Age":16,
	"Gender":"Female",
	"City": "Chennai"
}
print(student.values())
print("\n==== Values ====")
for v in student.values():
	print(" ",v)

Output

dict_values(['Tara', 130046, 458, 16, 'Female', 'Chennai'])

==== Values ====
  Tara
  130046
  458
  16
  Female
  Chennai