Python MCQ Questions Set-6

Here is an interesting Python Quiz. Attempting these Multiple choice questions will help you to evaluate your knowledge and skills.

  1. Which of the following commands will create a list?
    a) list1 = list()
    b) list1 = []
    c)list1=[1,2,3,4]
    d) all of the mentioned
  2. What is the output when we execute list(“hello”)?
    a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
    b) [‘hello’]
    c) [‘llo’]
    d) [‘olleh’]
  3. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
    a) 5
    b) 4
    c) None
    d) Error
  4. Suppose list1 is [2445,133,12454,123], what is max(list1)?
    a) 2445
    b) 133
    c) 12454
    d) 123
  5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?
    a) 3
    b) 5
    c) 25
    d) 1
  6. Suppose list1 is [1, 5, 9], what is sum(list1)?
    a) 1
    b) 9
    c) 15
    d) Error
  7. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is the correct syntax for slicing operation?
    a) print(list1[0])
    b) print(list1[:2])
    c) print(list1[:-2])
    d) all of the mentioned

  8. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
    a) [2, 33, 222, 14]
    b) Error
    c) 25
    d) [25, 14, 222, 33, 2]
  9. >>> names = [‘Amir’, ‘Bear’, ‘Charlton’, ‘Daman’]
    >>> names[-1][-1]
    a) A
    b) Daman
    c) Error
    d) n
  10.  To add a new element to a list we use which command?
    a) list1.add(5)
    b) list1.append(5)
    c) list1.addLast(5)
    d) list1.addEnd(5)
  11.  Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
    a) 0
    b) 1
    c) 4
    d) 2
  12. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
    a) 0
    b) 4
    c) 1
    d) 2

  1. names1 = [‘Amir’, ‘Bala’, ‘Chales’]
     
    if ‘amir’ in names1:
    print(1)
    else:
    print(2)
    a) None
    b) 1
    c) 2
    d) Error

  1. numbers = [1, 2, 3, 4]
     
    numbers.append([5,6,7,8])
     
    print(len(numbers))
    a) 4
    b) 5
    c) 8
    d) 12

  1. >>> numbers = [1, 2, 3, 4]

numbers.extend([5,6,7,8])
len(numbers)
a) 4
b) 5
c) 8
d) 12

  1. what is the output of following code?
    list1=[10,10,10,10]
    for x in list1:
    list1.remove(x)
    print(list1)
    a) [ ]
    b) [10,10,10,10]
    c) [10,10]
    d) Error
  2.  What will be the output of the following Python code?
    veggies = [‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]
    veggies.insert(veggies.index(‘broccoli’), ‘celery’)
    print(veggies)
    a) [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’] Correct 1.00
    b) [‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]

c) [‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]

d) [‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]

  1. What will be the output of the following Python code?
    m = [[x, x + 1, x + 2] for x in range(0, 3)]
    print(m)
    a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
    c) [1, 2, 3, 4, 5, 6, 7, 8, 9]
    d) [0, 1, 2, 1, 2, 3, 2, 3, 4]
  2. What will be the output of the following Python code snippet?
    print(‘ab\ncd\nef’.splitlines())
    a) [‘ab’, ‘cd’, ‘ef’]
    b) [‘ab\n’, ‘cd\n’, ‘ef\n’]
    c) [‘ab\n’, ‘cd\n’, ‘ef’]
    d) [‘ab’, ‘cd’, ‘ef\n’]
  3. What will be the output of the following Python code snippet?
    print(‘Ab!2’.swapcase())
    a) [email protected]
    b) ab12
    c) aB!2
    d) Error
  4. What will be the output of the following Python code snippet?
    print(‘ab cd-ef’.title())
    a) Ab cd-ef
    b) Ab Cd-ef
    c) Ab Cd-Ef
    d) None of the mentioned
  5. What will be the output of the following Python code snippet?
    print(‘abcdef12’.replace(‘cd’, ’12’))
    a) ab12ef12
    b) abcdef12
    c) ab12efcd
    d) none of the mentioned
  6. What will be the output of the following Python code snippet?
    print(‘abef’.replace(‘cd’, ’12’))
    a) abef
    b) 12
    c) error
    d) none of the mentioned

    26.What will be the output of the following Python code snippet?
    print(‘xyyxyyxyxyxxy’.replace(‘xy’, ’12’, 0))
    a) xyyxyyxyxyxxy
    b) 12y12y1212x12
    c) 12yxyyxyxyxxy
    d) xyyxyyxyxyx12

  1. What will be the output of the following Python code?
    print(‘[email protected]#World’.istitle())
    a) True
    b) False
    c) None
    d) error
  2. What will be the output of the following Python code snippet?
    print(‘abc’.islower())
    a) True
    b) False
    c) None
    d) Error
  3.  What will be the output of the following Python code?
    print(‘ab12’.isalnum())
    a) True
    b) False
    c) None
    d) Error
  4. What will be the output of the following Python code?
    print(‘ab,12’.isalnum())
    a) True
    b) False
    c) None
    d) Error
  5.  What will be the output of the following Python code?
    print(“ccdcddcd”.find(“c”))
    a) 4
    b) 0
    c) Error
    d) True
  6. What will be the output of the following Python code?
    print(“Hello {0} and {1}”.format(‘foo’, ‘bin’))
    a) Hello foo and bin
    b) Hello {0} and {1} foo bin
    c) Error
    d) Hello 0 and 1
  7.  What will be the output of the following Python code?
    print(“Hello {name1} and {name2}”.format(‘foo’, ‘bin’))
    a) Hello foo and bin
    b) Hello {name1} and {name2}
    c) Error
    d) Hello and
  8.  What will be the output of the following Python code?
    print(“Hello {} and {}”.format(‘foo’, ‘bin’))
    a) Hello foo and bin
    b) Hello {} and {}
    c) Error
    d) Hello and
  9. What will be the output of the following Python code?

str1=”helloworld”
str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld

  1.  Which of the following statement prints hello\example\test.txt?
    a) print(“hello\example\test.txt”)
    b) print(“hello\example\test.txt”)
    c) print(“hello\”example\”test.txt”)
    d) print(“hello”\example”\test.txt”)

  1. What will be the output of the following Python statement?

chr(ord(‘A’))
a) A
b) B
c) a
d) Error

  1.  What will be the output of the “hello” +1+2+3 ?
    a) hello123
    b) hello
    c) Error
    d) hello6
  2.  Which of the following is a Python tuple?
    a) [1, 2, 3]
    b) (1, 2, 3)
    c) {1, 2, 3}
    d) {}
  1. Suppose t = (1, 2, 4, 3), which of the following is incorrect?
    a) print(t[3])
    b) t[3] = 45
    c) print(max(t))
    d) print(len(t))
  2. What will be the output of the following Python code?

t=(1,2,4,3)
t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)

  1. What will be the output of the following Python code?
    t1 = (1, 2, 4, 3)
    t2 = (1, 2, 3, 4)
    t1 < t2
    a) True
    b) False
    c) Error
    d) None
  2. What will be the output of the following Python code?
    t = (1, 2)
    2 * t
    a) (1, 2, 1, 2)
    b) [1, 2, 1, 2]
    c) (1, 1, 2, 2)
    d) [1, 1, 2, 2]
  1. What will be the output of the following Python code?
    a=1,2,3,4
    print(a)

a) (1, 2, 3, 4)
b) 1
c) 4
d) 1,2,3,4

  1. What will be the output of the following Python code?

a=(1,2)
b=(3,4)
c=a+b
c
a) (4,6)
b) (1,2,3,4)
c) Error as tuples are immutable
d) None

  1. What will be the output of the following Python code?
    a=(2,3,1,5)
    a.sort()
    a
    a) (1,2,3,5)
    b) (2,3,1,5)
    c) None
    d) Error, tuple has no attribute sort
  1.  What will be the output of the following Python code?
    s1={3, 4}
    s2={1, 2}
    s3=set()
    i=0
    j=0
    for i in s1:
    for j in s2:
    s3.add((i,j))
    i+=1
    j+=1
    print(s3)
    a) {(3, 4), (1, 2)}
    b) Error
    c) {(4, 2), (3, 1), (4, 1), (5, 2)}
    d) {(3, 1), (4, 2)}

  1.  The __ function removes the first element of a set and the last element of a list.
    a) remove
    b) pop
    c) discard
    d) dispose

  1. What will be the output of the following Python code?

s=set([1, 2, 3])
s.union([4, 5])
print(s)
a){1, 2, 3}
b)[1,2,3]
c){1,2,3,4,5}
d)[1,2,3,4,5]

Leave a Comment