Python Quiz with solutions


To discuss, please use the comments below.

Question-

>>> x = 0 
>>> while x <= 18: 
          x = x + 3 
>>> print(x)

A. 18

B. 15

C. 21

D. 22

Question-

>>> x = [[0], [1]] 
>>> print((' '.join(list(map(str, x))),))

A. [0] [1]

B. 01

C. (’01’)

D. (‘[0] [1]’,)

Question-

>>> a = max(False, -3, -4) 
>>> b = min(a, 2, 7)
>>> print(b)

A. 2

B. a

C. -3

D. False

Question-

>>> def f1(): x = 100
return x
>>> x = f1() + 1
>>> print(x)

A. 1

B. 101

C. 100

D. Error

Question-

a = 65
print('[%c]' % a)

A. [a]
B. [A]
C. A
D. a

Make your python concepts more strong with our Python handwritten notes.

Question-

>>> a = 2*2//2 
>>> b = 3//2*3
>>> print(a, b)

A. 2 1

B. 3 2

C. 2 3

D. 2 2

Question-

>>> x, y = 67, 80 
>>> x, y, z = 1, 2, 3
>>> print(x, y, z)

A. 67 80 3

B. 1 2 3

C. Error

D. None of above

Question-

>>> b = 30 
>>> def fun(a, b=b):
return a+b
>>> print(fun(1))

A. 1

B. Error

C. 31

D. 30

Question-

>>> a = [0, 1, 2, 3] 
>>> for a[-1] in a:
print(a[-1])

A. 0 1 2 2

B. 0 1 2 3

C. 3 3 3 3

D. Error

Question-

>>> f=lambda x:bool(x%2) 
>>> print(f(20), f(21))

A. False False

B. Error

C. True False

D. False True

Question-

>>> a = 4/5 
>>> b = 5//4
>>> print(a * b)

A. 1.0

B. 1

C. 0.2

D. 0.8

Question-

>>> myList = ["python", "hub"] 
>>> for i in myList:
myList.append(i.upper())
>>> print(myList)

A. [“PYTHON”, “HUB”]

B. [“python”, “hub”]

C. Infinite loop

D. None of above

Question-

>>> a = 100 
>>> b = 5
>>> print(a//b*a/b)

A. 300.0

B. 400.0

C. 200.0

D. 100.0

Question-

>>> a = 100/5 
>>> b = 20//3
>>> print(a * b)

A. 120

B. 140

C. 140.0

D. 120.0

Question-

>>> def fun():
for x in range(22, 23, 24):
print(x)
>>> fun()

A. 21

B. 22

C. 23

D. 24

Question-

>>> a = ~4 
>>> b = a + 4
>>> print(b)

A. 1

B. -1

C. 2

D. -2

Make your python concepts more strong with our Python handwritten notes.

Question-

>>> def fun():
return 55 + int(55.55)
>>> print(fun())

A. 111

B. 110

C. 112

D. None of above

Question-

>>> a = "python" 
>>> b = "pythoN"
>>> print(a > b)

A. False

B. True

C. Error

D. None of these

Question-

>>> a = True 
>>> b = False
>>> print(a or a and b and a)

A. False

B. True

C. Error

D. None of above

Question-

>>> str1 = str("python") 
>>> str2 = "python"
>>> print(str1 == str2, str1 is str2)

A. True False

B. True True

C. False True

D. False False

Question-

>>> def add(a, b):
return a+5, b+5
>>> result=add(3, 2)
>>> print(result)

A. 8

B. 15

C. (8, 7)

D. Syntax Error

Question-

>>> a = 1/3 
>>> b = 3/1
>>> print(a * b)

A. 3

B. 3.0

C. 0.3

D. 1.0

Question-

>>> a = '2' 
>>> b = '2'
>>> print(a + b)

A. 4

B. 22

C. Error

D. 2

Question-

>>> a = [1, 2, 3] 
>>> b = a
>>> print(a is b, a == b)

A. True False

B. True True

C. False True

D. False False

Question-

>>> x = 0 
>>> while x < 20:
x = x + 3
>>> print(x)

A. 19

B. 18

C. 20

D. 21

Question-

>>> l = list("1234") 
>>> l[0] = l[1] = 5
>>> print(l)

A. [5, 5, ‘3’, ‘4’]

B. [‘5’, ‘5’, ‘3’, ‘4’]

C. [5, 5, 3, 4]

D. Error

Make your python concepts more strong with our Python handwritten notes.

Question-

>>> x=1 
>>> def cg():
global x
return x+1
>>> print(cg())

A. 1

B. 2

C. 0

D. Error

Question-

>>> e="butter"
>>> def f(a):
print(a)+e
>>> f("bitter")

A. butter error

B. bitterbutter

C. bitter error

D. Error

Question-

>>> a = 35 
>>> print(“%f”%a)

A. 34.0000

B. 34.00

C. 34.000000

D. 34.00000000

Question-

>>> def fun(): 
return [i for i in range(0, 3, 3)]
>>> print(fun())

A. [0, 1, 2]

B. [0, 1, 2, 3]

C. [0]

D. None of above

Question-

>>> def fun(): 
return "str " + 'char'
>>> print(fun())

A. “str ” ‘char’

B. str char

C. Error

D. None of above

Question-

>>> L = [1, 2, 3, 4] 
>>> for i in L[::1]:
print(i, end=" ")

A. 1 2 3 4

B. 4 3 2 1

C. Error

D. None of above

Question-

>>> def fun(): 
return pass
>>> print(fun())

A. SyntaxError

B. None

C. pass

D. None of above

Question-

>>> a = [10, 20] 
>>> b = a
>>> b += [30, 40]
>>> print(a)

A. [10, 20, [10, 20, 30, 40]]

B. [10, 20, 30, 40]

C. [10, 20, 30, 40, [10, 20]]

D. None of above

Question-

>>> a = 'python' 
>>> b = [1, 2, 3]
>>> aTup = (a, b)
>>> print(aTup[1][1:])

A. [2, 3]

B. Error

C. [1, 2, 3]

D. n, [2, 3]

Question-

>>> set1 = {1, 2, 3, int('4')} 
>>> set2 = {3, str(4)}
>>> print(set1.union(set2))

A. {1, 2, 3, 4}

B. {1, 2, 3, 4, ‘4’}

C. {1, 2, 3, ‘4’}

D. None of these

Question-

>>> def fun(a=12, b=12): 
print(a//9)
return (a*b)
>>> fun(a=9, b=2)

A. 0 18

B. 1 18

C. 1 24

D. Error

Question-

>>> print("abc. DEF".capitalize())

A. abc. def

B. Abc. def

C. Abc. Def

D. ABC. DEF

Question-

>>> l=[1,2,3,4,5] 
>>> value=[x&1 for x in l]
>>> print(value)

A. [1, 0, 0, 0, 0]

B. [1, 1, 1, 1, 1]

C. [1, 0, 1, 0, 1]

D. [0, 1, 0, 1, 0]

Question-

>>> z=set('abc') 
>>> z.add('san')
>>> z.update(set(['p', 'q']))
>>> print(z)

A. {‘abc’, ‘p’, ‘q’, ‘san’}

B. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}

C. {‘q’, ‘san’, ‘c’, ‘p’, ‘a’, ‘b’}

D. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}

Question-

>>> a = 5/5.5 
>>> b = 5*5.5
>>> print(a//b)

A. 30.0

B. 0

C. 0.0

D. 1.0

Question-

>>> dict1 = {"key1":1, "key2":2} 
>>> dict2 = {"key2":2, "key1":1}
>>> print(dict1 == dict2)

A. False

B. True

C. Error

D. None of above

Question-

>>> L = ['a','b','c','d']
>>> result = ''.join(L)
>>> print(result)

A. [abcd]

B. Error

C. abcd

D. a”b”c”d”

Question-

>>> aList = [5, 10, 15, 25] 
>>> print(aList[::-2])

A. [5, 10, 25]

B. Error

C. [5, 15, 25]

D. [25, 10]

Question-

>>> def fun():
             print('fun')
>>> print(fun())

A. None
fun

B. fun
None

C. fun
fun

D. Error

Answer-

B. fun
None

Explanation-

inside print() statement, we called fun() so fun() run and executes “print(‘fun’)” statement but fun() does not return anything so None will be printed by default.

Make your python concepts more strong with our Python handwritten notes.

Question-

>>> def x(values):
             values[0] = 1
>>> v = [2, 3, 4]
>>> x(v)
>>> print(v)

A. [1, 2, 3, 4]

B. [2, 3, 4]

C. [1, 3, 4]

D. None of above

Answer-

C. [1, 3, 4]

Explanation-

we simply changed list v using the function, it changes because we did not create any new variable here instead we assigned a new value using the “values[0] = 1” statement.

Question-

>>> f=lambda x:bool(x%2) 
>>> print(f(20), f(21))

A. False False

B. Error

C. True False

D. False True

Answer-

D. False True

Explanation-

lambda function accepting x as an argument, x%2 for even will return 0 that’s why bool(x%2) will return False and x%2 for odd will return 1 that’s why bool(x%2) will return True.


Leave a Reply

Your email address will not be published. Required fields are marked *