Knowee
Questions
Features
Study Tools

What will the output be of the following code?D = {1:['Raj', 22], 2:['Simran', 21], 3:['Rahul', 40]}for val in D: print(val)

Question

What will the output be of the following code?

D = {1: ['Raj', 22], 2: ['Simran', 21], 3: ['Rahul', 40]}
for val in D:
    print(val)
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given code will be:

1 2 3

Explanation: The code defines a dictionary D with three key-value pairs. Each key is an integer and each value is a list containing a name and an age.

The for loop iterates over the keys of the dictionary D. In each iteration, the current key is assigned to the variable val.

The print(val) statement prints the value of val in each iteration, which corresponds to the keys of the dictionary.

Therefore, the output will be the keys of the dictionary D, which are 1, 2, and 3, printed on separate lines.

This problem has been solved

Similar Questions

What will be the output of the following Python code?l=[[1, 2, 3], [4, 5, 6]]for i in range(len(l)): for j in range(len(l[i])): l[i][j]+=10print(l)

What will be the output of the following Python code?x = [[0], [1]]print(len(' '.join(list(map(str, x)))))

What is the output of below code snippeta = [ [8, 2] , [4, 1, 2, 2] ]b = a[1][2:]print(b)

What will be the output of the following Python code snippet?print([[i+j for i in "abc"] for j in "def"])

What will the output of the following program be?L1 = ['Vikas', 'Akshay', 'Sanskar', 'Mahima']print(L1[1][-1])

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.