FliQi Education App Download
विषय-वार प्रश्न-बैंक

Python — प्रश्न-बैंक

116 जाँचे हुए प्रश्न · 2 topics

Topics

और: History of Python · Identifier · Python Data Types · Operators · List (कम प्रश्न — app में)

किन परीक्षाओं में

नमूना प्रश्न

भाषा
प्रश्न 1उत्तर + हल Token and Keywords
Python programming में pass एक null statement है।
In Python programming, pass is a null statement.
  1. AहाँYes
  2. BनहींNo
  3. Cकह नहीं सकतेCan't say
  4. Dइनमें से कोई नहींNone of these

सही उत्तर / Answer: (A)

हल / Solution
pass Python का एक keyword है। यह चलने पर कुछ भी नहीं करता, इसलिए इसे null statement कहते हैं। Python में if, for, def या class के बाद कम से कम एक statement लिखना ज़रूरी है। जब वहाँ अभी कोई काम नहीं लिखना हो, तब pass रख देते हैं, जैसे def f(): pass। block ख़ाली छोड़ने पर IndentationError आता है। इसलिए कथन सही है और उत्तर 'हाँ' है।
pass is a Python keyword. When it runs it does nothing at all, so it is called a null statement. Python needs at least one statement after if, for, def or class. When you have nothing to write there yet, you put pass, for example def f(): pass. Leaving the block empty gives an IndentationError. So the statement is true and the answer is 'Yes'. The other options do not fit.
प्रश्न 2उत्तर + हल String
स्ट्रिंग s = "Hello" से index 3 वाला अक्षर पाने के लिए कौन-सा command चलाएँगे?
To retrieve the character at index 3 from string s = "Hello", which command do we execute?
  1. As[]
  2. Bs.getitem(3)
  3. Cs.__getitem__(3)
  4. Ds.getItem(3)

सही उत्तर / Answer: (C)

हल / Solution
जब हम s[3] लिखते हैं, तो Python अंदर से s.__getitem__(3) को ही बुलाता है। इसलिए s.__getitem__(3) सीधे चलाने पर भी index 3 का अक्षर मिलता है। "Hello" में index 3 पर l है। s[] में index लिखा ही नहीं, इसलिए यह SyntaxError देता है। getitem और getItem नाम के कोई method string में नहीं हैं, इसलिए ये AttributeError देते हैं। Python के ऐसे ख़ास method के नाम के दोनों तरफ़ दो underscore होते हैं।
When we write s[3], Python internally calls s.__getitem__(3). So running s.__getitem__(3) directly also returns the character at index 3. In "Hello", index 3 holds l. The option s[] has no index inside the brackets, so it is a SyntaxError. Strings have no methods named getitem or getItem, so both of those raise an AttributeError. Special methods like this always have two underscores on each side of the name, which the wrong options leave out.
प्रश्न 3उत्तर + हल
Python 3.0 का दूसरा नाम क्या है?
What is the other name of Python 3.0?
  1. AHL Module
  2. BPython 3
  3. CPy3k
  4. Dइनमें से कोई नहींNone of the above

सही उत्तर / Answer: (C)

हल / Solution
विकास के दौरान Python 3.0 को Python 3000 कहा गया, जिसका छोटा रूप Py3k है। Guido van Rossum ने यह नाम भाषा के उस बड़े बदलाव के लिए रखा था, जो पुराने कोड से पूरी तरह मेल नहीं खाता। यह संस्करण दिसंबर 2008 में जारी हुआ। 'Python 3' तो संस्करण का सीधा नाम है, दूसरा नाम नहीं। HL Module का पायथन के संस्करणों से कोई संबंध नहीं। Py3k सही है, इसलिए 'इनमें से कोई नहीं' भी ग़लत है।
During its development, Python 3.0 was known as Python 3000, or Py3k for short. Guido van Rossum used this name for the planned big cleanup of the language that would break backward compatibility. It was finally released in December 2008. 'Python 3' is just the plain version name, not a second name, and 'HL Module' has no link with Python versions. Since Py3k is correct, 'None of the above' is wrong.
प्रश्न 4उत्तर + हल
निम्नलिखित में से कौन-सा variable x को मान 7 के साथ घोषित करने और आरंभ करने का सही तरीका है?
Which one of the following is the correct way of declaring and initializing a variable x with the value 7?
  1. Aint x
    x=7
  2. Bint x=7
  3. Cx=7
  4. Ddeclare x=7

सही उत्तर / Answer: (C)

हल / Solution
Python एक dynamically typed भाषा है। यहाँ variable का type पहले से नहीं बताना पड़ता। मान देते ही variable बन जाता है और उसका type मान से तय होता है, इसलिए x=7 सही है। int x और int x=7 C या Java की शैली है; Python में इन पर SyntaxError आती है। declare Python का keyword नहीं है, इसलिए declare x=7 भी ग़लत है। इसलिए विकल्प C सही है।
Python is a dynamically typed language. You do not state the type of a variable in advance. A variable is created as soon as it gets a value, and its type comes from that value, so x=7 is correct. int x and int x=7 are C or Java style and give a SyntaxError in Python. declare is not a Python keyword, so declare x=7 is also wrong. So option C is correct.
प्रश्न 5उत्तर + हल
पायथन के data types के बारे में निम्नलिखित में से कौन-सा कथन ग़लत है?
Which one of the following is False regarding data types in Python?
  1. AIn python, explicit data type conversion is possible
  2. BMutable data types are those that can be changed
  3. CImmutable data types are those that cannot be changed
  4. DNone of the above

सही उत्तर / Answer: (D)

हल / Solution
तीनों कथन सही हैं, इसलिए कोई ग़लत नहीं बचता और उत्तर अंतिम विकल्प है। पहला कथन — पायथन में type casting से ख़ुद बदलाव किया जा सकता है, जैसे int("10") पाठ को संख्या बना देता है। दूसरा — mutable वही हैं जिनका सामान बदला जा सके, जैसे list, set और dictionary। तीसरा — immutable वे हैं जो बनने के बाद नहीं बदलते, जैसे int, float, str और tuple। तीनों पाठ्यपुस्तक की परिभाषाएँ हैं।
All three statements are true, so none of them is false and the last option becomes the answer. First, explicit conversion really is possible in Python through type casting, as int("10") turns text into a number. Second, mutable types are exactly those whose contents can be changed, such as list, set and dictionary. Third, immutable types cannot be changed once created, such as int, float, str and tuple. Each line matches the standard definition.
प्रश्न 6उत्तर + हल
“in” ऑपरेटर से निम्नलिखित में से किसमें यह जाँचा जा सकता है कि कोई item उसमें है या नहीं?
The “in” operator can be used to check whether an item is present in which of the following?
  1. AListLists
  2. BDictionary
  3. CSet
  4. Dउपरोक्त सभीAll of the mentioned

सही उत्तर / Answer: (D)

हल / Solution
in एक membership ऑपरेटर है। यह बताता है कि कोई item किसी collection में है या नहीं, और True या False देता है। list में यह हर element देखता है, जैसे 20 in [10, 20] का मान True है। set में भी यह इसी तरह चलता है। dictionary में यह keys देखता है, values नहीं: 'a' in {'a': 1} True है, पर 1 in {'a': 1} False। तीनों पर चलता है, इसलिए उत्तर 'उपरोक्त सभी' है।
The in keyword is a membership operator. It checks whether an item is present in a collection and returns True or False. With a list it checks every element, so 20 in [10, 20] is True. It works the same way with a set. With a dictionary it checks the keys, not the values: 'a' in {'a': 1} is True, but 1 in {'a': 1} is False. Since it works on all three, the answer is All of the mentioned.
प्रश्न 7उत्तर + हल
निम्नलिखित कोड का आउटपुट क्या होगा?
arr = [1,2,3,4,5,6]
print(arr[::2])
What will be the output of the following code?
arr = [1,2,3,4,5,6]
print(arr[::2])
  1. A[1,3,5]
  2. B[2,4,6]
  3. C[1,2]
  4. D[5,6]

सही उत्तर / Answer: (A)

हल / Solution
कटाई (slicing) का रूप है arr[start:stop:step]। यहाँ start और stop ख़ाली हैं, इसलिए पूरी सूची ली जाएगी, और step 2 है, इसलिए एक छोड़कर एक तत्व चुना जाएगा। क्रमांक 0, 2 और 4 के मान आएँगे, यानी 1, 3 और 5, इसलिए आउटपुट [1, 3, 5] है। [2,4,6] तब मिलता जब arr[1::2] लिखा होता। बाक़ी दो विकल्प इस सूची की किसी भी कटाई से नहीं बनते।
A slice is written as arr[start:stop:step]. Here start and stop are left empty, so the whole list is taken, and the step is 2, so every second element is picked. The values at index 0, 2 and 4 are selected, which are 1, 3 and 5, so the output is [1, 3, 5]. You would get [2,4,6] only from arr[1::2]. The other two options do not come out of any slice of this list.
प्रश्न 8उत्तर + हल
निम्नलिखित में से कौन गणितीय फंक्शन (mathematical function) है?
Which of the following refers to a mathematical function?
  1. Aadd
  2. Brhombus
  3. Csqrt
  4. DNone of the above

सही उत्तर / Answer: (C)

हल / Solution
sqrt का पूरा रूप square root है, यानी वर्गमूल। पायथन में यह math module में मिलता है — import math के बाद math.sqrt(25) चलाइए, उत्तर 5.0 आएगा। इसलिए यही गणितीय फंक्शन है। add जोड़ने की क्रिया का आम शब्द है; math module में इस नाम का कोई फंक्शन नहीं है। rhombus यानी समचतुर्भुज एक ज्यामितीय आकृति है, फंक्शन नहीं। सही विकल्प मौजूद है, इसलिए अंतिम विकल्प ग़लत है।
The name sqrt is short for square root. In Python it lives in the math module, so after import math the call math.sqrt(25) returns 5.0; this is clearly the mathematical function here. add is only the ordinary word for addition, and the math module has no function by that name. A rhombus is a geometric shape, not a function. Since a correct option is present, the last one is wrong too.
प्रश्न 9उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या है?
print((1, 2) + (3, 4))
What is the output of the following program?
print((1, 2) + (3, 4))
  1. A(1, 2), (3, 4)
  2. B(4, 6)
  3. C(1, 2, 3, 4)
  4. DInvalid Syntax

सही उत्तर / Answer: (C)

हल / Solution
दो टपल के बीच + लगाने पर अंकों का जोड़ नहीं होता, वे आगे-पीछे जुड़ जाते हैं। इसे concatenation कहते हैं। इसलिए (1, 2) और (3, 4) मिलकर नया tuple (1, 2, 3, 4) बनाते हैं और वही छपता है। (4, 6) तब मिलता जब तत्वों का अंकगणित होता, जो पायथन यहाँ नहीं करता। syntax पूरी तरह ठीक है, इसलिए Invalid Syntax ग़लत है। पुराने दोनों tuple वैसे ही बने रहते हैं।
Placing + between two tuples does not add their numbers; it joins the tuples one after the other, and this is called concatenation. So (1, 2) and (3, 4) together make the new tuple (1, 2, 3, 4), and that is what gets printed. You would see (4, 6) only if the elements were added pairwise, which Python does not do here. The syntax is legal, so Invalid Syntax is wrong, and both original tuples stay untouched.
प्रश्न 10उत्तर + हल
दिए गए कथन में निम्नलिखित में से कौन key हैं?
abc = {"first":10, "second":20}
Which of the following are the keys in the given statement?
abc = {"first":10, "second":20}
  1. A10, 20
  2. Bfirst, second
  3. Cfirst, 10, second, 20
  4. Dfirst, 20

सही उत्तर / Answer: (B)

हल / Solution
dictionary में कोलन से पहले वाला भाग key होता है और बाद वाला value। यहाँ कोलन से पहले "first" और "second" हैं, इसलिए वही key हैं, और 10 तथा 20 उनकी value हैं। जाँचने के लिए abc["first"] लिखिए, उत्तर 10 मिलेगा। तीसरा विकल्प key और value दोनों मिला देता है, और चौथे में एक key के साथ एक value रख दी गई है, इसलिए वे दोनों ग़लत हैं।
In a dictionary whatever stands before the colon is the key and whatever follows it is the value. Here "first" and "second" come before the colons, so they are the keys, while 10 and 20 are their values. You can test this with abc["first"], which returns 10. The third option mixes keys and values together, and the fourth pairs one key with one value, so neither of them answers the question.
Python का पूरा प्रश्न-बैंकहर topic के सारे प्रश्न, हल और अभ्यास — FliQi Question Bank app में