Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 2 : 3 / 3
Advertisement
Detailed Solution
सही उत्तर 3 / 3 है।
Key Points
Helpful?
Question:
What is the output of the following Python code involving a generator and next()? / जनरेटर और next() वाले निम्नलिखित Python कोड का आउटपुट क्या होगा? def gen(): yield 1; yield 2 g = gen() print(next(g) + next(g))
1.
1 / 1
2.
3 / 3
3.
[1, 2] / [1, 2]
4.
TypeError / TypeError
Correct Answer: 3 / 3
Each next() call resumes the generator and returns the next yielded value, so 1 + 2 = 3 is printed. / हर next() कॉल जनरेटर को आगे बढ़ाकर अगला yield किया मान देता है, अतः 1 + 2 = 3 छपता है।
Downloaded from PrepSnap (prepsnap.in)