Home / CSE MCQs / Python MCQs :: Python Lists & List Comprehension

CSE MCQs :: Python MCQs

  1. What is the output of the code shown below?

    import math
    [str(round(math.pi)) for i in range (1, 6)]
  2. A.
    ['3', '3', '3', '3', '3', '3']
    B.
    ['3.1', '3.14', '3.142', '3.1416', '3.14159', '3.141582']
    C.
    ['3', '3', '3', '3', '3']
    D.
    ['3.1', '3.14', '3.142', '3.1416', '3.14159']

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the output of the following?

    print([i.lower() for i in "HELLO"])
  4. A.
    ['h', 'e', 'l', 'l', 'o'].
    B.
    'hello'
    C.
    ['hello'].
    D.
    hello

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?
  6. A.
    3
    B.
    5
    C.
    25
    D.
    1

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Suppose list1 is [1, 3, 2], What is list1 * 2 ?
  8. A.
    [2, 6, 4].
    B.
    [1, 3, 2, 1, 3]
    C.
    [1, 3, 2, 1, 3, 2] .
    D.
    [1, 3, 2, 3, 2, 1]

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the output?

    names1 = ['Amir', 'Bala', 'Charlie']
    names2 = [name.lower() for name in names1]
     
    print(names2[2][0])
  10. A.
    None
    B.
    a
    C.
    b
    D.
    c

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What will be the output?

    values = [[3, 4, 5, 1], [33, 6, 1, 2]]
     
    v = values[0][0]
    for lst in values:
        for element in lst:
            if v > element:
                v = element
     
    print(v)
  12. A.
    1
    B.
    3
    C.
    5
    D.
    6

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output of the following code?

    import copy
    a=[10,23,56,[78]]
    b=copy.deepcopy(a)
    a[3][0]=95
    a[1]=34
    print(b)
  14. A.
    [10,34,56,[95]].
    B.
    [10,23,56,[78]].
    C.
    [10,23,56,[95]].
    D.
    [10,34,56,[78]].

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is the output of the following piece of code?

    a=list((45,)*4)
    print((45)*4)
    print(a)
  16. A.

    180

    [(45),(45),(45),(45)].

    B.

    (45,45,45,45).

    [45,45,45,45].

    C.

    180

    [45,45,45,45].

    D.
    Syntax error

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is the output of the code shown below?

    A = [[1, 2, 3],
         [4, 5, 6],
         [7, 8, 9]]
    [A[i][len(A)-1-i] for i in range(len(A))]
  18. A.
    [1, 5, 9]
    B.
    [4, 5, 6]
    C.
    [3, 5, 7]
    D.
    [2, 5, 8]

    View Answer

    Workspace

    Discuss Discuss in Forum