200 Most Important questions on Python's basics, including data types, variables, and input handling.
1. Which of the following is an immutable data type in Python?
a) List
b) Dictionary
c) Tuple
d) Set
Answer: c) Tuple
2. What is the correct syntax to declare a variable name with the value
"Sejal" in Python?
a) name: "Sejal"
b) name = "Sejal"
c) string name =
"Sejal"
d) name := "Sejal"
Answer: b) name = "Sejal"
3. What will be the output of the following code?
a = 10
b = 3.14
c = "Python"
print(type(b))
a) <class 'int'>
b) <class 'str'>
c) <class 'float'>
d) <class 'complex'>
Answer: c) <class 'float'>
4. How can you take user input in Python?
a) user_input = input("Enter your name: ")
b) user_input =
raw_input("Enter your name: ")
c) user_input =
input_string("Enter your name: ")
d) user_input =
read("Enter your name: ")
Answer: a) user_input =
input("Enter your name: ")
5. What will be the output of the following code?
x = 5
x = x + 10
print(x)
a) 5
b) 10
c) 15
d) 20
Answer: c) 15
6. Which of the following is a mutable data type in Python?
a) String
b) Tuple
c) List
d) Integer
Answer: c) List
7. What is the output of the following code?
var = "Python"
print(var[1:4])
a) Pyt
b) yth
c) tho
d) ytho
Answer: b) yth
8. What will be the type of the variable result in the following code?
result = 5 / 2
a) int
b) float
c) complex
d) str
Answer: b) float
9. Which of the following is not a valid variable name in Python?
a) my_var
b) _var1
c) 2var
d) var_2
Answer: c) 2var
10. What will be the output of the following code?
num1 = 4
num2 = 5
print(num1 * num2)
a) 9
b) 20
c) 45
d) 10
**Answer:** b) 20
11. Which of the following is a valid Python statement to declare a
variable age
with a value of
25?
a) int age = 25
b) age = 25
c) 25 = age
d) age := 25
Answer: b) age =
25
12. What is the output of the following code?
num =
7
print(num //
2)
a) 3
b) 3.5
c) 4
d) 2
Answer: a) 3
13. What data type is returned by the input()
function in Python?
a) int
b) float
c) str
d) list
Answer: c) str
14. What will be the output of the following code?
a =
"Hello"
b =
"World"
print(a +
" " + b)
a) HelloWorld
b) Hello World
c) Hello
d) World
Answer: b) Hello
World
15. What is the correct way to convert a string s = "123"
to an integer in
Python?
a) int(s)
b) str(s)
c) float(s)
d) s = 123
Answer: a) int(s)
16. What is the output of the following code?
print(
2 **
3)
a) 6
b) 8
c) 9
d) 12
Answer: b) 8
17. Which of the following is a valid Python list?
a) [1, 2, 3, 4]
b) (1, 2, 3, 4)
c) {1, 2, 3, 4}
d) 1, 2, 3, 4
Answer: a) [1, 2,
3, 4]
18. What will be the output of the following code?
x =
"python"
print(x.upper())
a) PYTHON
b) Python
c) python
d) PythoN
Answer: a) PYTHON
19. Which of the following is not a Python built-in data type?
a) set
b) array
c) tuple
d) list
Answer: b) array
20. What will be the output of the following code?
a =
10
b =
20
print(a < b)
a) True
b) False
c) None
d) Error
Answer: a) True
21. Which of the following Python keywords is used to create a variable?
a) var
b) let
c) def
d) None of the above
Answer: d) None of the above
22. What will be the output of the following code?
x =
15
y =
4
print(x % y)
a) 3
b) 1
c) 4
d) 11
Answer: a) 3
23. What is the data type of x
in the following code?
x =
"False"
a) bool
b) str
c) int
d) NoneType
Answer: b) str
24. Which of the following methods can be used to remove leading and
trailing whitespace from a string?
a) strip()
b) trim()
c) remove()
d) cut()
Answer: a) strip()
25. What will be the output of the following code?
print(
10 >
9)
a) True
b) False
c) None
d) 1
Answer: a) True
26. Which of the following is the correct way to declare a multi-line
string in Python?
a) "This is a multi-line
string"
b) '''This is a multi-line
string'''
c) """This is a
multi-line string"""
d) Both b) and c)
Answer: d) Both b) and c)
27. What will be the output of the following code?
x =
3
y =
"Python"
print(
str(x) + y)
a) Python3
b) 3Python
c) Error
d) TypeError
Answer: b) 3Python
28. Which of the following is a mutable data type in Python?
a) str
b) tuple
c) list
d) frozenset
Answer: c) list
29. What is the correct way to get the length of a string in Python?
a) length(s)
b) len(s)
c) size(s)
d) count(s)
Answer: b) len(s)
30. What will be the output of the following code?
print(
5 **
2)
a) 10
b) 25
c) 32
d) 52
Answer: b) 25
31. Which of the following is a valid dictionary in Python?
a) {1: "one", 2:
"two"}
b) [1, "one", 2,
"two"]
c) ("one", 1),
("two", 2)
d) {"one", 1,
"two", 2}
Answer: a) {1:
"one", 2: "two"}
32. What will be the output of the following code?
my_list = [
1,
2,
3,
4,
5]
print(my_list[
2])
a) 1
b) 2
c) 3
d) 4
Answer: c) 3
33. What is the result of the following code?
a =
"Hello"
print(a *
3)
a) HelloHelloHello
b) Hello3
c) Hello Hello Hello
d) Error
Answer: a) HelloHelloHello
34. Which of the following is the correct way to check the type of a
variable x
?
a) check(x)
b) type(x)
c) typeof(x)
d) is(x)
Answer: b) type(x)
35. What will be the output of the following code?
print(
10 /
3)
a) 3
b) 3.0
c) 3.33
d) 3.3333333333333335
Answer: d) 3.3333333333333335
36. Which of the following is not a valid Python operator?
a) +
b) -
c) ++
d) /
Answer: c) ++
37. What will be the output of the following code?
x = [
1,
2,
3,
4]
print(
len(x))
a) 3
b) 4
c) 5
d) 6
Answer: b) 4
38. Which of the following is a Python keyword?
a) True
b) false
c) None
d) nil
Answer: c) None
39. What will be the output of the following code?
print(
"10" +
"20")
a) 1020
b) 30
c) Error
d) None
Answer: a) 1020
40. What is the output of the following code?
x =
10
y = x %
3
print(y)
a) 1
b) 3
c) 7
d) 10
Answer: a) 1
41. Which of the following is a valid string in Python?
a) "Hello"
b) 'World'
c) '''Hello, World'''
d) All of the above
Answer: d) All of the above
42. What will be the output of the following code?
a =
5
b =
10
print(a != b)
a) True
b) False
c) None
d) Error
Answer: a) True
43. Which of the following can be used to iterate through a list in Python?
a) for
loop
b) while
loop
c) list comprehension
d) All of the above
Answer: d) All of the above
44. What will be the output of the following code?
my_list = [
1,
2,
3]
my_list.append(
4)
print(my_list)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) [1, 2, 4, 3]
Answer: b) [1, 2,
3, 4]
45. Which of the following is not a Python built-in function?
a) print()
b) input()
c) len()
d) append()
Answer: d) append()
46. What will be the output of the following code?
a =
5
b =
3
a, b = b, a
print(a, b)
a) 5 3
b) 3 5
c) 8 2
d) Error
Answer: b) 3 5
47. Which of the following methods is used to return a copy of a list?
a) copy()
b) list()
c) clone()
d) duplicate()
Answer: a) copy()
48. What is the output of the following code?
x =
"Python"
y =
"Programming"
print(x +
" " + y)
a) PythonProgramming
b) Python Programming
c) Python-Programming
d) Python, Programming
Answer: b) Python
Programming
49. Which of the following is the correct syntax for a Python function that
accepts a parameter name
?
a) def my_function: (name)
b) def my_function(name):
c) function my_function(name)
d) def my_function = (name)
Answer: b) def
my_function(name):
50. What will be the output of the following code?
a =
"5"
b =
"6"
print(
int(a) +
int(b))
a) 11
b) 56
c) 65
d) Error
Answer: a) 11
51. Which of the following is the correct way to declare a set in Python?
a) {}
b) []
c) ()
d) {1, 2, 3}
Answer: d) {1, 2,
3}
52. What will be the output of the following code?
x =
10
x +=
5
print(x)
a) 5
b) 10
c) 15
d) 20
Answer: c) 15
53. Which of the following is not a Python keyword?
a) elif
b) except
c) finally
d) switch
Answer: d) switch
54. What will be the output of the following code?
print(
bool(
0))
a) True
b) False
c) None
d) Error
Answer: b) False
55. Which of the following methods is used to convert a string to
lowercase?
a) lower()
b) down()
c) convert()
d) casefold()
Answer: a) lower()
56. What is the output of the following code?
print(
len(
"Hello World"))
a) 10
b) 11
c) 12
d) 9
Answer: b) 11
57. Which of the following is not a valid list method?
a) append()
b) extend()
c) insert()
d) add()
Answer: d) add()
58. What will be the output of the following code?
x = [
1,
2,
3,
4,
5]
print(x[
1:
3])
a) [1, 2, 3]
b) [2, 3]
c) [3, 4]
d) [4, 5]
Answer: b) [2, 3]
59. What is the correct way to declare a constant in Python?
a) constant PI = 3.14
b) PI = 3.14
c) const PI = 3.14
d) PI := 3.14
Answer: b) PI =
3.14
60. What will be the output of the following code?
print(
2 +
3 *
4)
a) 14
b) 20
c) 24
d) 9
Answer: a) 14

61. Which of the following is the correct way to declare an empty
dictionary in Python?
a) dict = {}
b) dict = []
c) dict = ()
d) dict = set()
Answer: a) dict =
{}
62. What will be the output of the following code?
x =
"Hello"
print(x *
2)
a) HelloHello
b) Hello2
c) Hello 2
d) Error
Answer: a) HelloHello
63. Which of the following is a valid Python comment?
a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <!-- This is a comment -->
Answer: c) # This
is a comment
64. What will be the output of the following code?
print(
"Python" +
"Programming")
a) Python Programming
b) PythonProgramming
c) Python-Programming
d) Python, Programming
Answer: b) PythonProgramming
65. Which of the following is the correct way to declare a multi-line
string in Python?
a) "This is a multi-line
string"
b) '''This is a multi-line
string'''
c) "This is a multi-line
string"
d) multi_line_string()
Answer: b) '''This
is a multi-line string'''
66. What will be the output of the following code?
x =
5
y =
10
print(x == y)
a) True
b) False
c) None
d) Error
Answer: b) False
67. Which of the following is a valid Python integer?
a) 1.0
b) 100
c) True
d) "123"
Answer: b) 100
68. What will be the output of the following code?
x =
5.0
print(
type(x))
a) <class 'int'>
b) <class 'float'>
c) <class 'str'>
d) <class 'list'>
Answer: b) <class
'float'>
69. Which of the following is the correct way to convert a float f = 3.14
to an integer in Python?
a) int(f)
b) str(f)
c) float(f)
d) f = 3
Answer: a) int(f)
70. What will be the output of the following code?
print(
bool(
"False"))
a) True
b) False
c) None
d) Error
Answer: a) True

71. Which of the following is the correct way to get a character from a
string s = "Python"
at index 2?
a) s[2]
b) s(2)
c) s.index(2)
d) s.charAt(2)
Answer: a) s[2]
72. What will be the output of the following code?
print(
7 %
2)
a) 1
b) 2
c) 7
d) 3.5
Answer: a) 1
73. Which of the following methods can be used to convert a string to
uppercase in Python?
a) upper()
b) uppercase()
c) capitalize()
d) toUpper()
Answer: a) upper()
74. What will be the output of the following code?
print(
10 //
3)
a) 3
b) 3.33
c) 3.3333333333333335
d) 3.0
Answer: a) 3
75. Which of the following is not a Python operator?
a) *
b) /
c) #
d) //
Answer: c) #
76. What will be the output of the following code?
print(
type(
5))
a) <class 'float'>
b) <class 'int'>
c) <class 'str'>
d) <class 'list'>
Answer: b) <class
'int'>
77. Which of the following is a correct way to declare a floating-point
number in Python?
a) x = 10.0
b) x = 10
c) x = "10"
d) x = [10.0]
Answer: a) x =
10.0
78. What will be the output of the following code?
print(
10 /
2)
a) 5
b) 5.0
c) 10
d) None
Answer: b) 5.0
79. Which of the following is a correct variable name in Python?
a) 2name
b) name_2
c) name@2
d) name-2
Answer: b) name_2
80. What will be the output of the following code?
x =
5
print(x ==
5.0)
a) True
b) False
c) None
d) Error
Answer: a) True

81. Which of the following is not a valid Python list method?
a) append()
b) pop()
c) remove()
d) add()
Answer: d) add()
82. What will be the output of the following code?
x =
"Hello"
y = x[
1:
4]
print(y)
a) Hel
b) ell
c) llo
d) lo
Answer: b) ell
83. Which of the following is the correct syntax for a dictionary
comprehension in Python?
a) {k: v for k in iterable}
b) [k: v for k in iterable]
c) (k: v for k in iterable)
d) {k, v for k in iterable}
Answer: a) {k: v
for k in iterable}
84. What will be the output of the following code?
a =
"5.5"
b =
float(a)
print(b)
a) 5
b) 5.5
c) "5.5"
d) Error
Answer: b) 5.5
85. Which of the following is a valid way to check if a key exists in a
dictionary?
a) if key in dictionary:
b) if key exists in dictionary:
c) if dictionary.has_key(key):
d) if key in dictionary.keys():
Answer: a) if key
in dictionary:
86. What will be the output of the following code?
x =
10
y =
2
print(x ** y)
a) 12
b) 20
c) 100
d) 1024
Answer: c) 100
87. Which of the following is not a Python built-in data type?
a) dict
b) tuple
c) array
d) set
Answer: c) array
88. What will be the output of the following code?
a = [
1,
2,
3]
b = a.copy()
b.append(
4)
print(a)
a) [1, 2, 3, 4]
b) [1, 2, 3]
c) [4, 1, 2, 3]
d) Error
Answer: b) [1, 2,
3]
89. Which of the following is the correct way to create an empty set in
Python?
a) set = {}
b) set = ()
c) set = []
d) set = set()
Answer: d) set =
set()
90. What will be the output of the following code?
a = [
1,
2,
3]
print(a[-
1])
a) 1
b) 2
c) 3
d) Error
Answer: c) 3

91. Which of the following is the correct way to create a tuple in Python?
a) x = (1, 2, 3)
b) x = [1, 2, 3]
c) x = {1, 2, 3}
d) x = 1, 2, 3
Answer: a) x = (1,
2, 3)
92. What will be the output of the following code?
a =
"Hello"
print(a[
0:
2])
a) Hel
b) He
c) ll
d) lo
Answer: b) He
93. Which of the following is a correct way to delete a key-value pair from
a dictionary?
a) del dictionary[key]
b) dictionary.remove(key)
c) dictionary.delete(key)
d) dictionary.pop(key)
Answer: a) del
dictionary[key]
94. What will be the output of the following code?
x = [
1,
2,
3,
4,
5]
print(x[
1::
2])
a) [1, 2, 3, 4, 5]
b) [2, 4]
c) [1, 3, 5]
d) [2, 3, 4]
Answer: b) [2, 4]
95. Which of the following is the correct way to declare a frozen set in
Python?
a) frozen_set = {}
b) frozen_set = frozenset([1, 2,
3])
c) frozen_set = set([1, 2, 3])
d) frozen_set = frozenset()
Answer: b) frozen_set
= frozenset([1, 2, 3])
96. What will be the output of the following code?
a = [
1,
2,
3]
a[
0] =
10
print(a)
a) [10, 2, 3]
b) [1, 2, 3]
c) [10, 1, 2, 3]
d) Error
Answer: a) [10, 2,
3]
97. Which of the following is the correct way to create a list
comprehension in Python?
a) [x for x in iterable]
b) {x for x in iterable}
c) (x for x in iterable)
d) list(x for x in iterable)
Answer: a) [x for
x in iterable]
98. What will be the output of the following code?
a =
"Python"
print(a[
2:])
a) Py
b) Pyt
c) ython
d) on
Answer: c) ython
99. Which of the following is not a valid Python string method?
a) replace()
b) find()
c) lower()
d) pop()
Answer: d) pop()
100. What will be the output of the following code?
a =
"Hello, World!"
print(a.replace(
"World",
"Python"))
a) Hello, Python!
b) Hello, World!
c) Hello, Python
d) Python, World!
Answer: a) Hello,
Python!
101. Which of the following is the correct way to declare a global variable
in Python?
a) global x = 10
b) x = 10
c) global x; x = 10
d) x := 10
Answer: c) global
x; x = 10
102. What will be the output of the following code?
a =
5
b =
10
c =
15
print(a < b < c)
a) True
b) False
c) None
d) Error
Answer: a) True
103. Which of the following is not a valid Python tuple method?
a) count()
b) index()
c) append()
d) len()
Answer: c) append()
104. What will be the output of the following code?
print(
"Python".upper())
a) PYTHON
b) python
c) Python
d) PythoN
Answer: a) PYTHON
105. Which of the following is a correct way to unpack a tuple in Python?
a) a, b = (1, 2)
b) a, b = [1, 2]
c) a, b = {1, 2}
d) a, b = 1, 2
Answer: a) a, b =
(1, 2)
106. What will be the output of the following code?
x =
5
print(
not x ==
5)
a) True
b) False
c) None
d) Error
Answer: b) False
107. Which of the following is the correct way to declare a list of
integers in Python?
a) x = {1, 2, 3}
b) x = [1, 2, 3]
c) x = (1, 2, 3)
d) x = "1, 2, 3"
Answer: b) x = [1,
2, 3]
108. What will be the output of the following code?
x =
3.5
print(
int(x))
a) 3
b) 3.5
c) 4
d) Error
Answer: a) 3
109. Which of the following is a valid Python list slicing operation?
a) x[::-1]
b) x[::2]
c) x[1:5]
d) All of the above
Answer: d) All of the above
110. What will be the output of the following code?
a =
"Hello"
print(a[-
2:])
a) lo
b) He
c) ll
d) Hello
Answer: a) lo

111. Which of the following is the correct way to create a dictionary in
Python?
a) x = {1: "one",
2: "two"}
b) x = [1: "one", 2:
"two"]
c) x = (1: "one", 2:
"two")
d) x = {"one": 1,
"two": 2}
Answer: a) x = {1:
"one", 2: "two"}
112. What will be the output of the following code?
a = {
1,
2,
3,
4,
5}
a.add(
6)
print(a)
a) {1, 2, 3, 4, 5, 6}
b) [1, 2, 3, 4, 5, 6]
c) {6, 1, 2, 3, 4, 5}
d) Error
Answer: a) {1, 2,
3, 4, 5, 6}
113. Which of the following is the correct way to remove an element from a
list by its value?
a) x.pop(value)
b) x.remove(value)
c) x.delete(value)
d) x.discard(value)
Answer: b) x.remove(value)
114. What will be the output of the following code?
a = [
1,
2,
3]
a.extend([
4,
5])
print(a)
a) [1, 2, 3, 4, 5]
b) [1, 2, 3]
c) [4, 5]
d) [1, 2, 3, [4, 5]]
Answer: a) [1, 2,
3, 4, 5]
115. Which of the following is the correct way to convert an integer to a
string in Python?
a) str(x)
b) int(x)
c) float(x)
d) chr(x)
Answer: a) str(x)
116. What will be the output of the following code?
print(
len([
1,
2,
3,
4,
5]))
a) 4
b) 5
c) 6
d) Error
Answer: b) 5
117. Which of the following is the correct way to get the length of a
string in Python?
a) length(str)
b) len(str)
c) size(str)
d) count(str)
Answer: b) len(str)
118. What will be the output of the following code?
print(
"Hello".isupper())
a) True
b) False
c) None
d) Error
Answer: b) False
119. Which of the following is a valid Python boolean expression?
a) a == b
b) a < b
c) a != b
d) All of the above
Answer: d) All of the above
120. What will be the output of the following code?
a =
5
b =
5
print(a
is b)
a) True
b) False
c) None
d) Error
Answer: a) True

121. Which of the following is the correct way to check if a string s contains only digits?
a) s.isdigit()
b) s.isnumeric()
c) s.isalpha()
d) s.isdecimal()
Answer: a) s.isdigit()
122. What will be the output of the following code?
a = [1, 2, 3]
b = a
b.append(4)
print(a)
a) [1, 2, 3, 4]
b) [1, 2, 3]
c) []
d) Error
Answer: a) [1, 2, 3, 4]
123. Which of the following is not a valid Python string method?
a) startswith()
b) endswith()
c) capitalize()
d) append()
Answer: d) append()
124. What will be the output of the following code?
x = 5
y = 10
print(x + y)
a) 15
b) 50
c) 510
d) Error
Answer: a) 15
125. Which of the following is the correct way to declare a complex number
in Python?
a) x = 5 + 2j
b) x = 5 + 2i
c) x = 5 + 2k
d) x = complex(5, 2)
Answer: a) x = 5 + 2j
126. What will be the output of the following code?
a = "Python"
b = a[::-1]
print(b)
a) nohtyP
b) Python
c) PythoN
d) None
Answer: a) nohtyP
127. Which of the following is the correct way to get the absolute value of
a number in Python?
a) abs()
b) fabs()
c) math.abs()
d) math.fabs()
Answer: a) abs()
128. What will be the output of the following code?
a = [1, 2, 3, 4, 5]
print(a[1:4])
a) [1, 2, 3, 4, 5]
b) [2, 3, 4]
c) [3, 4, 5]
d) [1, 3, 5]
Answer: b) [2, 3, 4]
129. Which of the following is not a valid Python dictionary method?
a) get()
b) keys()
c) items()
d) slice()
Answer: d) slice()
130. What will be the output of the following code?
a = 10
b = 5
print(a // b)
a) 2
b) 2.0
c) 5
d) 0
Answer: a) 2
131. Which of the following is the correct way to check if a list a contains the value 3?
a) if 3 in a:
b) if a.contains(3):
c) if a.has(3):
d) if 3 is in a:
Answer: a) if 3 in a:
132. What will be the output of the following code?
a = "Hello"
print(a[::2])
a) Hlo
b) el
c) Hello
d) Hloel
Answer: a) Hlo
133. Which of the following is the correct way to remove all elements from
a list in Python?
a) a.clear()
b) a.removeAll()
c) a.del()
d) a.popAll()
Answer: a) a.clear()
134. What will be the output of the following code?
a = {1, 2, 3}
b = {3, 4, 5}
print(a & b)
a) {3}
b) {1, 2, 3, 4, 5}
c) {}
d) None
Answer: a) {3}
135. Which of the following is a correct way to concatenate two lists in
Python?
a) a + b
b) a.extend(b)
c) a.append(b)
d) a.join(b)
Answer: a) a + b
136. What will be the output of the following code?
a = [1, 2, 3]
b = a * 2
print(b)
a) [1, 2, 3]
b) [1, 2, 3, 1, 2, 3]
c) [2, 4, 6]
d) [1, 2, 3, 6]
Answer: b) [1, 2, 3, 1, 2, 3]
137. Which of the following is the correct way to check the type of a
variable in Python?
a) type(x)
b) typeof(x)
c) isinstance(x)
d) checktype(x)
Answer: a) type(x)
138. What will be the output of the following code?
a = [1, 2, 3, 4, 5]
print(a[-1])
a) 1
b) 5
c) [5]
d) Error
Answer: b) 5
139. Which of the following is the correct way to declare a variable in
Python?
a) x = 10
b) var x = 10
c) int x = 10
d) let x = 10
Answer: a) x = 10
140. What will be the output of the following code?
a = "Python"
b = "3"
print(a + b)
a) Python3
b) Python 3
c) PythonThree
d) Error
Answer: a) Python3
141. Which of the following is not a valid Python set method?
a) add()
b) remove()
c) update()
d) replace()
Answer: d) replace()
142. What will be the output of the following code?
x = 10
y = 20
z = 5
print(x > y > z)
a) True
b) False
c) None
d) Error
Answer: b) False
143. Which of the following is the correct way to get the minimum value
from a list a?
a) min(a)
b) a.min()
c) a.minimum()
d) a.minValue()
Answer: a) min(a)
144. What will be the output of the following code?
a = [1, 2, 3]
b = a.pop()
print(b)
a) [1, 2]
b) 3
c) 1
d) 2
Answer: b) 3
145. Which of the following is not a valid Python list method?
a) insert()
b) pop()
c) split()
d) index()
Answer: c) split()
146. What will be the output of the following code?
a = [1, 2, 3]
a.insert(1, 4)
print(a)
a) [1, 4, 2, 3]
b) [1, 2, 3, 4]
c) [4, 1, 2, 3]
d) [1, 2, 3]
Answer: a) [1, 4, 2, 3]
147. Which of the following is the correct way to declare a float variable
in Python?
a) x = 10.5
b) x = float(10)
c) x = 10
d) Both a) and b)
Answer: d) Both a) and b)
148. What will be the output of the following code?
a = "Python"
print(a.replace("P", "J"))
a) Jython
b) Python
c) JythonP
d) PythoN
Answer: a) Jython
149. Which of the following is the correct way to check if a list a is empty?
a) if not a:
b) if len(a) == 0:
c) if a == []:
d) All of the above
Answer: d) All of the above
150. What will be the output of the following code?
a = [1, 2, 3]
a.reverse()
print(a)
a) [3, 2, 1]
b) [1, 2, 3]
c) 321
d) Error
Answer: a) [3, 2, 1]
151. Which of the following is a mutable data type in Python?
a) list
b) tuple
c) str
d) int
Answer: a) list
152. What will be the output of the following code?
a = {1, 2, 3}
b = {4, 5, 6}
print(a | b)
a) {1, 2, 3, 4, 5, 6}
b) {1, 2, 3}
c) {4, 5, 6}
d) Error
Answer: a) {1, 2, 3, 4, 5, 6}
153. Which of the following is the correct way to declare a set in Python?
a) x = {1, 2, 3}
b) x = [1, 2, 3]
c) x = (1, 2, 3)
d) x = "1, 2, 3"
Answer: a) x = {1, 2, 3}
154. What will be the output of the following code?
a = [1, 2, 3]
b = a.copy()
b.append(4)
print(a)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) []
d) Error
Answer: a) [1, 2, 3]
155. Which of the following is not a valid Python string operation?
a) concatenation
b) multiplication
c) division
d) indexing
Answer: c) division
156. What will be the output of the following code?
a = "123"
b = int(a)
print(b)
a) 123
b) 1, 2, 3
c) None
d) Error
Answer: a) 123
157. Which of the following is a correct way to find the index of an
element in a list a?
a) a.index(x)
b) a.find(x)
c) a.search(x)
d) a.locate(x)
Answer: a) a.index(x)
158. What will be the output of the following code?
a = "Python"
print(a[:2])
a) Py
b) on
c) Python
d) Error
Answer: a) Py
159. Which of the following is not a valid Python numeric data type?
a) int
b) float
c) str
d) complex
Answer: c) str
160. What will be the output of the following code?
a = [1, 2, 3]
b = len(a)
print(b)
a) 3
b) 2
c) 1
d) 0
Answer: a) 3
161. Which of the following is the correct way to convert a string to
lowercase in Python?
a) str.lower()
b) str.upper()
c) str.title()
d) str.swapcase()
Answer: a) str.lower()
162. What will be the output of the following code?
a = [1, 2, 3]
b = a[1:]
print(b)
a) [2, 3]
b) [1, 2]
c) [1, 2, 3]
d) []
Answer: a) [2, 3]
163. Which of the following is the correct way to check if a key k is in a dictionary d?
a) if k in d:
b) if d.contains(k):
c) if d.has(k):
d) if k is in d:
Answer: a) if k in d:
164. What will be the output of the following code?
a = "Python"
print(a[-1])
a) n
b) P
c) o
d) Error
Answer: a) n
165. Which of the following is a valid Python tuple operation?
a) concatenation
b) multiplication
c) indexing
d) All of the above
Answer: d) All of the above
166. What will be the output of the following code?
a = "123"
b = float(a)
print(b)
a) 123.0
b) 123
c) 1, 2, 3
d) Error
Answer: a) 123.0
167. Which of the following is the correct way to create a new list from
another list a without modifying a?
a) b = a[:]
b) b = a
c) b = copy(a)
d) b = deepcopy(a)
Answer: a) b = a[:]
168. What will be the output of the following code?
a = {1: "one", 2: "two"}
b = a[2]
print(b)
a) two
b) one
c) 1
d) 2
Answer: a) two
169. Which of the following is not a valid Python dictionary operation?
a) retrieving
b) updating
c) deleting
d) slicing
Answer: d) slicing
170. What will be the output of the following code?
a = "Python"
b = a.find("y")
print(b)
a) 1
b) 2
c) 0
d) -1
Answer: a) 1
171. Which of the following is the correct way to remove a key-value pair
from a dictionary in Python?
a) del d[k]
b) d.pop(k)
c) d.remove(k)
d) Both a) and b)
Answer: d) Both a) and b)
172. What will be the output of the following code?
a = [1, 2, 3]
b = a[0]
print(b)
a) 1
b) [1]
c) 0
d) Error
Answer: a) 1
173. Which of the following is the correct way to create a set with a
single element 1?
a) x = {1}
b) x = [1]
c) x = (1,)
d) x = "1"
Answer: a) x = {1}
174. What will be the output of the following code?
a = {1, 2, 3}
a.add(4)
print(a)
a) {1, 2, 3, 4}
b) {1, 2, 3}
c) {4}
d) None
Answer: a) {1, 2, 3, 4}
175. Which of the following is a correct way to convert a list to a tuple
in Python?
a) tuple(a)
b) a.tuple()
c) list(a)
d) tuple[a]
Answer: a) tuple(a)
176. What will be the output of the following code?
a = "Python"
b = a.upper()
print(b)
a) PYTHON
b) python
c) Python
d) PytHON
Answer: a) PYTHON
177. Which of the following is the correct way to check if two variables a and b refer to the same
object?
a) a is b
b) a == b
c) a identical b
d) a equals b
Answer: a) a is b
178. What will be the output of the following code?
a = "Python"
print(a.split("t"))
a) ['Py', 'hon']
b) ['Python']
c) ['P', 'y', 't', 'h', 'o',
'n']
d) ['t']
Answer: a) ['Py', 'hon']
179. Which of the following is not a valid Python set operation?
a) union
b) intersection
c) difference
d) concatenation
Answer: d) concatenation
180. What will be the output of the following code?
a = [1, 2, 3]
a.clear()
print(a)
a) []
b) [1, 2, 3]
c) None
d) Error
Answer: a) []
181. Which of the following is the correct way to declare a boolean
variable in Python?
a) x = True
b) x = bool(1)
c) x = bool(True)
d) All of the above
Answer: d) All of the above
182. What will be the output of the following code?
a = [1, 2, 3]
b = a[-2]
print(b)
a) 2
b) 1
c) 3
d) Error
Answer: a) 2
183. Which of the following is not a valid Python list operation?
a) append
b) extend
c) insert
d) removeAt
Answer: d) removeAt
184. What will be the output of the following code?
a = "123"
b = a.isdigit()
print(b)
a) True
b) False
c) 1
d) Error
Answer: a) True
185. Which of the following is a correct way to remove all elements from a
set in Python?
a) a.clear()
b) a.removeAll()
c) a.del()
d) a.popAll()
Answer: a) a.clear()
186. What will be the output of the following code?
a = [1, 2, 3]
b = a.pop(1)
print(a)
a) [1, 3]
b) [2, 3]
c) [1, 2]
d) [1, 2, 3]
Answer: a) [1, 3]
187. Which of the following is the correct way to get the maximum value
from a list a?
a) max(a)
b) a.max()
c) a.maximum()
d) a.maxValue()
Answer: a) max(a)
188. What will be the output of the following code?
a = "Python"
b = len(a)
print(b)
a) 6
b) 5
c) 4
d) Error
Answer: a) 6
189. Which of the following is not a valid Python string method?
a) count()
b) find()
c) format()
d) clear()
Answer: d) clear()
190. What will be the output of the following code?
a = {1: "one", 2: "two"}
a[3] = "three"
print(a)
a) {1: "one", 2: "two", 3: "three"}
b) {1: "one", 2:
"two"}
c) {3: "three"}
d) Error
Answer: a) {1: "one", 2:
"two", 3: "three"}
191. Which of the following is a correct way to get the number of elements
in a list a?
a) len(a)
b) a.length()
c) a.size()
d) a.count()
Answer: a) len(a)
192. What will be the output of the following code?
a = "Python"
print(a.capitalize())
a) Python
b) PYTHON
c) python
d) P
Answer: a) Python
193. Which of the following is the correct way to remove a value v from a list a?
a) a.remove(v)
b) a.pop(v)
c) a.del(v)
d) a.delete(v)
Answer: a) a.remove(v)
194. What will be the output of the following code?
a = [1, 2, 3]
b = sum(a)
print(b)
a) 6
b) 5
c) 4
d) 3
Answer: a) 6
195. Which of the following is not a valid Python dictionary method?
a) keys()
b) values()
c) items()
d) clear()
Answer: d) clear()
196. What will be the output of the following code?
a = "Python"
b = a.count("o")
print(b)
a) 1
b) 2
c) 0
d) Error
Answer: a) 1
197. Which of the following is the correct way to get the last element of a
list a?
a) a[-1]
b) a.last()
c) a.end()
d) a.tail()
Answer: a) a[-1]
198. What will be the output of the following code?
a = [1, 2, 3]
b = a + [4, 5]
print(b)
a) [1, 2, 3, 4, 5]
b) [1, 2, 3]
c) [4, 5]
d) Error
Answer: a) [1, 2, 3, 4, 5]
199. Which of the following is the correct way to check if a string a starts with the letter P?
a) a.startswith("P")
b) a.starts("P")
c) a.first("P")
d) a.beginswith("P")
Answer: a) a.startswith("P")
200. What will be the output of the following code?
a = "Python"
b = a.isalpha()
print(b)
a) True
b) False
c) 1
d) Error
Answer: a) True
Download PDF oof this MCQ questions by given the following link.
Download PDF of all this Question 👈👈
Our Other Sources:-👇👇👇👇
Thankyou so much friends for visiting and learn from here. If you like this set of questions, then share it with your friends through social media as Instagram, Facebook, Whatsapp and other social media platforms.
Thanks