MCQ Bank
What does lst.pop(1) do in [10, 20, 30]?
- A) Deletes 20
- B) Raises an error
- C) Deletes 30
- D) Deletes 10
What does lst[:2] return in [10, 20, 30]?
- A) [20, 30]
- B) [10, 20, 30]
- C) [30]
- D) [10, 20]
What does Python's consistency refer to in handling data structures?
- A) Python only supports immutable data structures
- B) Lists and strings are treated as mutable
- C) Lists and strings are immutable
- D) Similar operations are available for different data structures
How would you unpack a list l = [1, 2, 3] into individual variables?
- A) a, *b = l
- B) a, b = l
- C) a, b, c = l
- D) a = l[0], b = l[1]
In which scenario "set" is most useful?
- A) When you need to store unique elements
- B) When you need to modify elements in place
- C) When you need to access elements by index
- D) When you need to preserve the order of elements
Which of the following is a property of sets in Python?
- A) Sets are ordered
- B) Sets can contain only numbers
- C) Sets do not allow duplicate elements
- D) Sets allow duplicate elements
Which of the following methods is used to find the number of occurrences of an element in a tuple?
- A) count()
- B) search()
- C) len()
- D) index()
Which of the following is true about variable-length unpacking in Python?
- A) The * operator can be used with strings and tuples, but not lists
- B) You can only use * with lists
- C) The * operator captures all remaining elements during unpacking
- D) You cannot use * for unpacking a tuple
Which method is used to add a single element to a set?
- A) insert()
- B) push()
- C) append()
- D) add()
How can you repeat the elements of a tuple (1, 2) three times?
- A) (1, 2) * 3
- B) tuple(1, 2).repeat(3)
- C) (1, 2) + 3
- D) (1, 2).repeat(3)
How can multiple elements be added to a set at once?
- A) add()
- B) extend()
- C) update()
- D) append()
What happens when a duplicate element is added to a set?
- A) The set throws an error
- B) The set grows in size
- C) The duplicate is added at the end
- D) The duplicate is ignored
Which of the following is true about iterating through a set?
- A) You cannot iterate over a set
- B) Sets are indexed, and you can use the index to iterate
- C) Sets support list slicing for iteration
- D) Sets are unordered, so iteration may not follow insertion order
How can you find the index of element 30 in a tuple t = (10, 20, 30, 40)?
- A) t.search(30)
- B) t.index(30)
- C) index(t, 30)
- D) find(30, t)
Which of the following statement is correct about Marshalling?
- A) Used to write data in XML documents
- B) Used to read data from XML documents
- C) None of the given
- D) Can be used for both writing/reading purposes
Which of the following method get called at the beginning of a document in SAX parsing?
- A) startDocument()
- B) None of the given options.
- C) documentStart()
- D) initDocument()
Methods such as startDocument, endDocument, startElement, and endElement are invoked by ____________.
- A) Error Handler
- B) Content Handler
- C) Default Handler
- D) DTD Handler
Which of the following methods is used in JDOM Parser to get all the direct child nodes of an element?
- A) Element.getChildren()
- B) Node.getChild()
- C) Node.getChildren()
- D) Document.getChildren()
A ______________ implements the ContentHandler, ErrorHandler, DTDHandler, and EntityResolver interfaces.
- A) Content Handler
- B) Default Handler
- C) Error Handler
- D) DTD Handler
Which method does SAX use for processing XML documents?
- A) Event Based
- B) DocumentHandler
- C) Document
- D) Tree Based