Python Online Quiz - Part -1

Our Python Online Quiz is an individual for various tests and interviews. Questions have detailed problem descriptions and solutions with detailed explanations so that one can understand them easily.

1. Which of the following is not a core data type in Python programming?

Lists
Dictionary
Class
Tuples

2. What will be the output of the following Python function?

len(["hello",2, 4, 6])
6
Error
3
4

3. What will be the value of ‘result’ in following Python program?

list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(i for i in list3 if i not in (list1+list2) and i not in result)
[1, 2, 4, 7, 8]
[1, 3, 5, 7, 8]
[1, 7, 8]
Error

4. What will be the output of the following Python program?

i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)
0 1 2
0 1 2 0
Error
none of the mentioned

5. What is output of print(math.pow(3, 2))?

9
0.9
9.0
None

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

def foo():
    try:
        return 1
    finally:
        return 2
k = foo()
print(k)
error, there is more than one return statement in a single try-finally block
1
2
3

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

print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))
Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
Hello foo and bin
Error
None of the mentioned

8. What will be the output of the following Python program?

  1. def addItem(listParam):
  2.     listParam += [1]
  3.  
  4. mylist = [1, 2, 3, 4]
  5. addItem(mylist)
  6. print(len(mylist))
1
2
8
5

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

x = 'abcd'
for i in range(len(x)):
    print(i)
0 1 2 3
1 2 3 4
a b c d
error

10. What will be the output of the following Python program?

def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
True
False
None
Error