Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 3 : [0, 4, 16]
Advertisement
Detailed Solution
सही उत्तर [0, 4, 16] है।
Key Points
Helpful?
Question:
What does the following Python list-comprehension code output? / सूची बोध वाले निम्नलिखित Python कोड का आउटपुट क्या है? nums = [x * x for x in range(5) if x % 2 == 0] print(nums)
1.
[1, 9]
2.
[0, 1, 4, 9, 16]
3.
[0, 4, 16]
4.
[4, 16]
Correct Answer: [0, 4, 16]
range(5) gives 0 to 4; the condition keeps the even values 0, 2, 4; squaring gives [0, 4, 16]. Many forget that 0 is even and contributes 0. / range(5) से 0 से 4 मिलते हैं; शर्त सम मान 0, 2, 4 रखती है; वर्ग करने पर [0, 4, 16] मिलता है। बहुत से लोग भूल जाते हैं कि 0 सम है और 0 देता है।
Downloaded from PrepSnap (prepsnap.in)