Python Questions
Python Questions
A - 'o'
B - 't'
C - 'h'
D - Negative index error.
Answer: C
A - int(144)==144
B - int('144')==144
C - int(144.0)==144
D - None of the above
Answer : D
s = 0
for d in range(0, 5, 0.1):
… s += d
… print(s)
A - Syntax Error
B - Type Error
C - Runtime Error
D - Both b & c
Answer : D
A. True
B. False
Answer : A
A. True
B. False
Answer : A
A. True
B. False
Answer : B
Q7. c -= a is equivalent to
A. c = a - c
B. c = c - a
C. a = c - a
D. a = a - c
Answer : B
Q8. c *= a is equivalent to
A. c = c * a
B. a = c * a
C. c = c / a
D. a = c / a
Answer : A
Q9. c /= a is equivalent to
A. c = c / a
B. c = c * a
C. a = c * a
D. a = a / c
Answer : A
Q10. c %= a is equivalent to
A. c = c % a
B. a = c % a
C. a = a % c
D. c = a % c
Answer : A
Q11. c += a is equivalent to
A. c = c + a
B. a = c + a
C. a = a + c
D. c = a + c
Answer : A,D
A. James Gosling
B. Denis Richie
C. Guido Van Rossum
D. Ramus Lerdorf
Answer : C
A. Yes
B. No
Answer: B
A. int(x)
B. long(x)
C. float(x)
D. flaot(x)
E. str(x)
Answer: C
A. Float division
B. Integer division
C. returns the remainder
D. same as a**b
Answer: B
A. function
B. try
C. def
D. import
Answer: C
Q17. Which function is used to open the file for reading in python?
A. fopen(filename,mode)
B. open(filename,mode)
C. openfile(filename,mode)
D. opne_file(filename,mode)
Answer: B
A. tuples
B. list
C. both are mutable
D. none of above
Answer: B
A. chr
B. char
C. character
D. python do not have any data type for characters they are treated as string
Answer: D
Q20. In python which is the correct method to load a module?
A. include sqlite3
B. import sqlite3
C. #include sqlite3
D. using sqlite3
Answer: B
A. True
B. Flase
Answer: A
A. Yes
B. No
Answer: A
A. 2
B. 17
C. 0
D. None above
Answer: D
A. 2
B. 17
C. 19
D. 1
Answer: D
A. my_string_1
B. 1st_string
C. foo
D. _
Answer: B
A. abc = 1,000,000
B. a b c = 1,000,000
C. a,b,c = 1,000,000
D. a_b_C = 1,000,000
Answer: B
Q27. Which one of these is floor division?
A. /
B. //
C. %
D. None of the mentioned
Answer: B
A. 7
B. 1
C. 0
D. 5
Answer: B
A. 27
B. 9
C. 3
D. 1
Answer: C
Q30. The expression Int(x) implies that the variable x is converted to integer.
A. True
B. False
Answer: A
>>>str="hello"
>>>str[:2]
>>>
A. he
B. lo
C. olleh
D. hello
Answer: A
Q32. What will be the output of the following Python code snippet?
>>>def example(a):
... a = a + '2'
... a = a*2
... return a
>>>example("hello")
A. indentation Error
B. cannot perform mathematical operation on strings
C. hello2
D. hello2hello2
Answer: A
A. list
B. dictionary
C. array
D. tuple
Answer: A
Q34. What will be the output of the following Python code snippet?
>>>"Hello"*2
A. 'Hello*2'
B. 'Hello2'
C. 'HelloHello'
D. 'Hel'
Answer: C
Q35. What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
A. 85.0
B. 85.1
C. 95.0
D. 85
Answer: A
hello-how-are-you
Answer: C
A. int
B. bool
C. float
D. None
Answer: A
4 + 3 % 5
A. 4
B. 7
C. 2
D. 0
Answer: B
x = int(43.55+2/2)
A. 43
B. 44
C. 22
D. 23
Answer: B
A. /
B. %
C. //
D. |
Answer: C
8/4/2, 8/(4/2)
A. (1.0, 4.0)
B. (1.0, 1.0)
C. (4.0. 1.0)
D. (4.0, 4.0)
Answer: A
A - 'pyt'
B - 'thon'
C - 'h'
D - Index error.
Answer: A
A - 'pyt'
B - 'hon'
C - 'h'
D - Index error.
Answer: B
A - 'py'
B - 'ho'
C - 'tho'
D - Index error.
Answer: B
A - 'p'
B - 'y'
C - 'ython'
D - Index error.
Answer: B
A - 'p'
B - 'y'
C - 'ython'
D - Index error.
Answer: A
A - 'p'
B - 'y'
C - 'ython'
D - Index error.
Answer: C
A - 'p'
B - 'y'
C - 'ython'
D - 'h'
Answer: D
Q49. Python is Case Insensitive.
A. True
B. Flase
Answer: B
A. 10
B. 5
C. 4
D. None above
Answer: D
A. 2
B. 10
C. 4
D. 0
Answer: D
Q52. What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) // 2
A. 85.0
B. 85
C. 84.0
D. 84
Answer: B
A. True
B. Flase
Answer: B
A. 10
B. 5
C. 4
D. None above
Answer: D
Q55. What will be the output of 25 % 2 in python?
A. 2
B. 10
C. 5
D. 1
Answer: D
A. 5
B. 7
C. 9
D. 10
Answer: A
A. 1
B. 30
C. 20
D. 10
Answer: B
A - 'Sat'
B - 'turday'
C - 't'
D - 'day'
Answer: A
A - 'Sat'
B - 'day'
C - 't'
D - 'tur'
Answer: B
A - 'Sa'
B - 'tu'
C - 'urda'
D - 'rday'
Answer: B
A - 'd'
B - 'u'
C - 'r'
D - Index error.
Answer: B
A - 'Sat'
B - 'Satur'
C - 'urday'
D - Index error.
Answer: A
A - 'Sat'
B - 'Satur'
C - 'urday'
D - Index error.
Answer: C
A - 'u'
B - 'S'
C - 't'
D - 'd'
Answer: D
A. 2
B. 10
C. 5
D. 1
Answer: D
A. 6
B. 1
C. 9
D. 4
Answer: A
A. 1
B. 0
C. 5
D. 6
Answer: C
A. 7
B. 34
C. 43
D. '3+4'
Answer: B
Q69. Which of the following symbols are used for comments in Python?
A. //
B. ''
C. /**/
D. #
Answer: D
A. length()
B. len()
C. strlen()
D. stringlength()
Answer: B
Q71. Python allows string slicing. What is the output of below code:
s='Breakfast'
print(s[3:5])
A. 'st'
B. 'ak'
C. 'ea'
D. 'fa'
Answer: B
Q72. How to find the last element of list in Python? Assume `bikes` is the name of
list.
A. bikes[0]
B. bikes[-1]
C. bikes[lpos]
D. bikes[:-1]
Answer: B
Q73. If a='IPMC', b='GHANA' then which of the following operation would show
'IPMCGHANA' as output?
A. a+b
B. a+''+b
C. a+""+b
D. All of the above
Answer: D
A. IPMC
B. IPMCGHANA-GHANA
C. TypeError: unsupported operand
D. None of the above
Answer: C
A. 4.3
B. 4.0
C. 4
D. compilation error
Answer: B
Q76. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
A. Error
B. 25
C. None
D. 2
Answer: B
Answer: C
A. 0
B. 1
C. 2
D. 0.5
Answer: C
>>>str="ipmcghana"
>>>str[:4]
A. pmcg
B. ghan
C. ipmc
D. hana
Answer: C
A. Tuple
B. Array
C. Dictionary
D. List
Answer: D
Q81. Which of the following data type is used to store values in Key & Value
format?
A. Class
B. List
C. Tuple
D. Dictionary
Answer: D
A. print('ipmc-' + 'ghana');
B. print('ipmc' + '-ghana');
C. print('ipmc' + '-' + 'ghana');
D. All of the above
Answer: D
A. Yes
B. No
C. Depends on Python Version
Answer: A
Answer: D
A. var@
B. 32var
C. def
D. abc_a_c
Answer : D
A. if a>=2 :
B. if (a >= 2)
C. if (a => 22)
D. if a >= 22
Answer: A
Q87. What keyword would you use to add an alternative condition to an if statement?
A. else if
B. elseif
C. elif
D. None of these
Answer: C
A. Yes
B. No
Answer: A
Answer : B
A. True
B. False
Answer: B
Q91. Suppose a list with name arr, contains 5 elements. You can get the 2nd element
from the list using:
A. arr[-2]
B. arr[2]
C. arr[1]
D. arr[-1]
Answer: C
Q92. How to get last element of list in python? Suppose we have list with name arr,
contains 5 elements.
A. arr[0]
B. arr[5]
C. arr[last]
D. arr[-1]
Answer: D
A. define
B. fun
C. def
D. function
Answer: C
A. 2.0
B. 2.25
C. 9.0
D. 20.25
E. 21
Answer: A
A. 1
B. 2
C. 4
D. 5
E. 7
Answer: C
x = True
y = False
z = False
if x or y and z:
print("yes")
else:
print("no")
A. yes
B. no
C. fails to compile
Answer: A
x = True
y = False
z = False
if not x or y:
print(1)
elif not x or not y and z:
print(2)
elif not x or y or not y and x:
print(3)
else:
print(4)
A. 1
B. 2
C. 3
D. 4
Answer: C
A. [6, 5, 4]
B. 2
C. 7
D. [3, 2, 1]
Answer: D
Answer: B
Answer: C