प्रोग्रामिङ – Programming MCQ
प्रोग्रामिङ – कम्प्युटर र IT
Programming · Computer & IT (Technical) · १,५६५ प्रश्न
१,५६५ प्रश्न उपलब्ध। मोड छान्नुहोस्:
प्रोग्रामिङ: प्रश्न र उत्तर
सही लागेको विकल्पमा थिच्नुहोस्। सही भए हरियो, गलत भए रातो देखिन्छ; ३ सेकेन्डपछि सही उत्तर र व्याख्या देखिन्छ।
सही: ० / ०
-
What is the output of the Python code: s = set(); s.add((1, 2)); s.add((2, 1)); s.add((1, 2)); print(len(s)) ?
सही उत्तर: ख) 2
Tuples are hashable and order matters, so (1, 2) and (2, 1) are different; the repeated (1, 2) is ignored.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Testing the truth value of None, a zero float and a one-space string in Python: what does print(bool(None), bool(0.0), bool(' ')) display?
सही उत्तर: घ) False False True
None and 0.0 are falsy, but a string containing a space is non-empty and therefore truthy.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python: try: x = [1, 2][2] / except IndexError: x = -1 / finally: x += 10. What does print(x) display afterwards?
सही उत्तर: घ) 9
Index 2 is out of range, so x = -1; the finally block always runs and adds 10, giving 9.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, class Bag stores self.items = [1, 2, 3] in __init__ and defines __len__(self) returning len(self.items). What does print(len(Bag()) * 2) display?
सही उत्तर: क) 6
len() calls the object's __len__ method, which returns 3, and 3 * 2 = 6.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, class A defines f() returning 'A', class B(A) defines nothing new, class C(A) overrides f() to return 'C', and class D(B, C) is empty. What does print(D().f()) display?
सही उत्तर: ग) C
Python's method resolution order for D is D, B, C, A, so C.f is found before A.f.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, class A has __init__ setting self.v = 1 and a method inc(self) that does self.v += 1 and returns self. What does print(A().inc().inc().v) display?
सही उत्तर: घ) 3
Because inc() returns the same object, the calls can be chained; v goes from 1 to 3.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
What is the output of the Python code: nums = [1, 2, 3, 4, 5]; print(nums[1::2], nums[::-2]) ?
सही उत्तर: क) [2, 4] [5, 3, 1]
[1::2] starts at index 1 with step 2; [::-2] starts from the end with step -2.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Python string formatting with the percent presentation type: what does print('{:.1%}'.format(0.256)) display?
सही उत्तर: ख) 25.6%
The % format multiplies by 100 and adds a percent sign, here with one decimal place.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, def make(k): return lambda x: x * k. After double = make(2), what does print(double(double(5))) display?
सही उत्तर: क) 20
The returned function remembers k = 2 (a closure), so double(5) = 10 and double(10) = 20.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, def f(n): return [] if n == 0 else f(n - 1) + [n]. What does print(f(3)) display?
सही उत्तर: ख) [1, 2, 3]
f(3) = f(2) + [3] = (f(1) + [2]) + [3] = [1] + [2] + [3] = [1, 2, 3].
💬 टिप्पणी / गल्ती रिपोर्ट (०)
यी अभ्यास प्रश्न हुन्, आधिकारिक प्रश्न होइनन्। पाठ्यक्रम, विज्ञापन र नतिजाका लागि सम्बन्धित निकायको आधिकारिक वेबसाइट हेर्नुहोस्। उत्तरमा गल्ती भेटे प्रश्नमुनिको "टिप्पणी / गल्ती रिपोर्ट" मा लेख्नुहोस्।
नमस्ते! पाठ्यक्रम, सामान्य ज्ञान, भाषा परीक्षा वा कुनै प्रश्नको उत्तर बुझ्न सोध्नुहोस्।
AI ले गल्ती गर्न सक्छ। महत्वपूर्ण कुरा आधिकारिक स्रोतमा जाँच्नुहोस्।