Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 4 : 10 4 / 10 4

Advertisement

Detailed Solution

सही उत्तर 10 4 / 10 4 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Python code involving dict get() and setdefault()? / dict के get() और setdefault() वाले निम्नलिखित Python कोड का आउटपुट क्या होगा? d = {'x': 1, 'y': 2} d['z'] = d.get('x', 0) + d.setdefault('w', 9) print(d['z'], len(d))

1.
10 3 / 10 3
2.
9 4 / 9 4
3.
1 4 / 1 4
4.
10 4 / 10 4

Correct Answer: 10 4 / 10 4

get returns 1 for 'x', and setdefault inserts 'w' with value 9 and returns 9, so d['z'] = 10; the dictionary now holds four keys. / 'x' के लिए get 1 देता है और setdefault 'w' को 9 मान के साथ जोड़कर 9 लौटाता है, अतः d['z'] = 10; डिक्शनरी में अब चार कुंजियाँ हैं।

Downloaded from PrepSnap (prepsnap.in)