Python MCQ-2



  1. Which of the following sequence data type is defined by enclosing the elements in parentheses ‘()’?
    1. Lists
    2. Arrays
    3. Tuples
    4. Dictionary

  2. Which of the following statement is not valid about Numpy ‘Arrays’?
    1. The type of items in the array is specified by a separate data-type object (dtype)
    2. numpy arrays are immutable
    3. numpy arrays can support multidimensional data
    4. ndarray.shape attribute returns a tuple consisting of array dimensions

  3. The command to access the last element from the array “a” is?

    import array as arr
    a = arr.array('d',[2.5,3.5,4.5])

    1. print (a[0])
    2. print (a[3])
    3. print (a[-1])
    4. print (a)

  4. Create an array ‘x’ with values 0 to 9 and find what is the command to extract the elements in the following sequence - array ([5,3,1])?
    1. x = np.arange(10); x[5,3,1]
    2. x = np.arange(10); x[-5::2]
    3. x = np.arange(10); x[5:-2]
    4. x = np.arange(10); x[5::-2]

  5. What will be the output after executing the following codes?

    x = (0,8,9,15,17,18)
    y = slice(1,-2)
    x[y]

    1. 0,8,9,15
    2. 8,9,15,17
    3. 8,9,15
    4. IndexError

  6. The method used to increase the length of the list by number of elements in its argument.
    1. add ()
    2. insert ()
    3. extend ()
    4. pop ()

  7. The function that returns the indices of the sorted elements.
    1. np.argsort ()
    2. np.sort ()
    3. np.bogosort ()
    4. np.selectionsort ()

  8. Create two tuples

    tuple = (2,4,6,3,7)
    tuple1 = (1,2,3)

    Find out which of the following code does not work on a tuple
    1. tuple+tuple1
    2. sum(tuple)
    3. tuple[3] = 45
    4. len(tuple)

  9. The command to find the number of elements in the following array “N” is

    N = np.array([24, None, 29, 'str', np.nan, 23, 20, (), [], ...])

    1. len(N)
    2. N.count()
    3. np.size(N)
    4. N.size()

  10. Which of the following is not a valid syntax for creating a Set ‘M’ in Python?
    1. M = set ([11,12,12,13,14,15])
    2. M = {11,12,13,14}
    3. M = set ([11,12],[13,14],[14,15])
    4. M = set ((11,12,13,14))

  11. What will be the output after executing the following codes?

    S = {12,13,14,15}
    S.intersection_update({17,13,14,16});
    print(S)

    1. Error, object has no attribute intersection_update
    2. S={12,13,14,15,16, 17}
    3. S={12,13,14,15}
    4. S={13,14}

  12. Which of the following command returns the set of all elements from both sets, a and b?
    1. a ^ b
    2. a & b
    3. a | b
    4. a – b

  13. What will be the output of ndarray.ndim attribute?
    1. Gives the size of each element of the array in bytes
    2. Gives the number of axes or dimensions of the array
    3. Gives the buffer containing the actual elements of the array
    4. Gives an object describing the type of the elements in the array

  14. For dictionary d = {“plum ":0.66, "pears ":1.25,"oranges ":0.50, “apple”:0.75 }, which of the following statement correctly updates the price of oranges to 0.90?
    1. d[2] = 0.90
    2. d[0.50] = 0.90
    3. d["oranges "] = 0.90
    4. d["plum "] = 0.90

  15. Which of the following command(s) is/are used to join arrays?
    1. np.concatenate
    2. np.hstack
    3. np.vstack
    4. all of the above

  16. What will be the output of the dictionary ‘c’?

    c={}
    c[1]=1
    c['1']=2
    c[1]+=1
    print(c)

    1. { 1: 1 }
    2. { 1: 2, '1': 2 }
    3. { 1: 0; ‘1’: 2 }
    4. { 1: 1, '1': 2 }

  17. The output of the code given below is

    n = [x*x for x in range(4)]
    print(n)

    1. [1, 4, 9]
    2. [1, 4, 9, 16]
    3. [0, 1, 4, 9]
    4. [0, 1, 4, 9, 16]

  18. The output of the code given below is

    list = [2, 4, 6, 8]
    a = (x**3 for x in list)
    print(next(a))

    1. 4
    2. 6
    3. 8
    4. 64

  19. Which of the following is not possible in sequence datatypes?
    1. Create a tuple inside a set
    2. Create a list inside a set
    3. Create a list inside a tuple
    4. Create a set inside a list

  20. Which of the following commands will give you a new numpy array with Boolean values?
    1. np.ones((3,3),True)
    2. np.zeros((3,3),False)
    3. np.arange((3,3),False)
    4. np.full((3,3),True)

No comments:

Post a Comment