Quiz Home
Python_i_quiz3 Quiz
1: What is the result of slicing a list in Python, and how does it differ from copying the entire list?
  Slicing creates a new list, copying references the same list
  Slicing and copying both create shallow copies
  Slicing creates a shallow copy, copying creates a deep copy
  Slicing creates a deep copy, copying creates a shallow copy



2: In Python, how does a bytearray differ from a bytes object?
  bytearray is mutable, bytes is immutable
  bytes is mutable, bytearray is immutable
  There is no difference
  bytearray is used for text data, bytes for binary data



3: What is the primary use of a 'Counter' object in the 'collections' module?
  To count the occurrence of each element in an iterable
  To ensure thread-safe operations on data
  To implement a timer
  To count the number of iterations in a loop



4: When would you use a 'defaultdict' instead of a regular dictionary in Python?
  When you need to store items in order
  When keys being searched might not exist
  When you need to perform complex calculations on keys
  When the dictionary needs to be immutable



5: What is the difference between 'append()' and 'extend()' methods in Python lists?
  'append()' adds a single element, 'extend()' adds multiple elements
  'extend()' adds a single element, 'append()' adds multiple elements
  There is no difference
  'append()' is faster than 'extend()'



6: In Python, what is 'dictionary comprehension'?
  A method to iterate over dictionaries
  A syntax to create dictionaries from iterables
  A built-in function for sorting dictionaries
  A module for handling complex dictionary operations



7: What is the purpose of the 'chain' function in the itertools module?
  To link multiple iterators together
  To create combinations of elements
  To repeat an iterator a specified number of times
  To filter elements from an iterator



8: How is 'OrderedDict' different from a regular dictionary in Python?
  OrderedDict maintains the order of insertion
  OrderedDict is faster
  There is no difference as of Python 3.7
  OrderedDict allows duplicate keys



9: What is the function of the '__iter__' method in Python?
  To initialize an object
  To return an iterator from an object
  To perform iteration in a for loop
  To modify the behavior of an iterator



10: In Python, how does 'enumerate' function enhance the functionality of a loop?
  By adding a counter to an iterable
  By speeding up the loop
  By reducing memory usage in the loop
  By reversing the order of the loop