प्रोग्रामिङ – Programming MCQ
प्रोग्रामिङ – कम्प्युटर र IT
Programming · Computer & IT (Technical) · १,५६५ प्रश्न
१,५६५ प्रश्न उपलब्ध। मोड छान्नुहोस्:
प्रोग्रामिङ: प्रश्न र उत्तर
सही लागेको विकल्पमा थिच्नुहोस्। सही भए हरियो, गलत भए रातो देखिन्छ; ३ सेकेन्डपछि सही उत्तर र व्याख्या देखिन्छ।
सही: ० / ०
-
In Python, x = 10 is set at module level and def f(): x = 20 is defined. After calling f(), what does print(x) display?
सही उत्तर: ख) 10
Assigning to x inside f creates a new local variable; without the global keyword the module-level x is unchanged.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
What is the output of the Python code: a = [1, 2, 3, 4, 5]; a[1:3] = [9]; print(a) ?
सही उत्तर: ख) [1, 9, 4, 5]
Slice assignment replaces the two elements at indices 1 and 2 with the single element 9, so the list shrinks.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
What is the output of the Python code: print([i * j for i in range(1, 3) for j in range(1, 3)]) ?
सही उत्तर: ग) [1, 2, 2, 4]
The first for is the outer loop: i = 1 gives 1, 2 and i = 2 gives 2, 4.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
What is the output of the Python code: print(not 0 and 5) ?
सही उत्तर: घ) 5
not binds more tightly than and: not 0 is True, and True and 5 returns its second operand, 5.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, a class P defines def __str__(self): return 'P!'. What does print(P()) display?
सही उत्तर: क) P!
print() converts an object to text by calling its __str__ method.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python, class A defines hi() returning 'A', and class B(A) overrides hi() to return 'B' + super().hi(). What does print(B().hi()) display?
सही उत्तर: क) BA
super().hi() calls the parent's version, which returns 'A', and it is joined after 'B'.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In Python: class A: n = 0 (a class attribute). After a = A(); b = A(); a.n = 5, what does print(A.n, b.n) display?
सही उत्तर: ख) 0 0
a.n = 5 creates a new instance attribute on a only; the class attribute A.n, which b also sees, stays 0.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
What is the output of the Python code: fs = [lambda: i for i in range(3)]; print([f() for f in fs]) ?
सही उत्तर: ग) [2, 2, 2]
Each lambda looks up i when it is called, not when it is created (late binding), and by then i is 2.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
A Python function f has a try block containing return 1 and a finally block containing return 2. What does f() return?
सही उत्तर: घ) 2
The finally block always runs before the function exits, and a return inside it overrides the return value of the try block.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
What is the output of the Python code: print('abc' < 'abd', 'Z' < 'a') ?
सही उत्तर: घ) True True
Strings are compared character by character by code point: 'c' < 'd', and 'Z' (90) < 'a' (97).
💬 टिप्पणी / गल्ती रिपोर्ट (०)
यी अभ्यास प्रश्न हुन्, आधिकारिक प्रश्न होइनन्। पाठ्यक्रम, विज्ञापन र नतिजाका लागि सम्बन्धित निकायको आधिकारिक वेबसाइट हेर्नुहोस्। उत्तरमा गल्ती भेटे प्रश्नमुनिको "टिप्पणी / गल्ती रिपोर्ट" मा लेख्नुहोस्।
नमस्ते! पाठ्यक्रम, सामान्य ज्ञान, भाषा परीक्षा वा कुनै प्रश्नको उत्तर बुझ्न सोध्नुहोस्।
AI ले गल्ती गर्न सक्छ। महत्वपूर्ण कुरा आधिकारिक स्रोतमा जाँच्नुहोस्।