Python
Python is a high-level, interpreted programming language known for its readability, simplicity, and versatility. It supports multiple programming paradigms, including object-oriented, procedural, and functional programming. Python is widely used for web development, data analysis, artificial intelligence, automation, and scientific computing.
Is Python code compiled or interpreted?
a) Python code is both compiled and interpreted ✅
b) Python code is neither compiled nor interpreted
c) Python code is only compiled
d) Python code is only interpretedWhat does pip stand for in Python?
a) Pip Installs Python
b) Pip Installs Packages
c) Preferred Installer Program ✅
d) All of the mentionedWhat will be the output of the following Python function? min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False ✅What are the two main types of functions in Python?
a) System function
b) Custom function
c) Built-in function & User defined function ✅
d) User functionIs Python case sensitive when dealing with identifiers?
a) No
b) Yes ✅
c) Machine dependent
d) None of theseWhich of the following functions can help us to find the version of Python that we are currently working on?
a) sys.version(1)
b) sys.version(0)
c) sys.version()
d) sys.version ✅Python supports the creation of anonymous functions at runtime, using a construct called ____
a) pi
b) anonymous
c) lambda ✅
d) none of theseWhat is the order of precedence in Python?
a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction ✅Which of the following is true for variable names in Python?
a) Underscore and ampersand are the only two special characters allowed
b) Unlimited length ✅
c) All private members must have leading and trailing underscores
d) None of the mentionedWhich of the following is the use of id() function in Python?
a) Every object doesn’t have a unique id
b) Id returns the identity of the object ✅
c) All of the mentioned
d) None of the mentioned
11. Which of the following is a mutable data type in Python?
a) List ✅
b) Tuple
c) String
d) Integer
12. Which of the following is used to define a block of code in Python?
a) Indentation ✅
b) Curly braces
c) Parentheses
d) None of the mentioned
13. What is the correct way to declare a list in Python?
a) list = ()
b) list = {}
c) list = [] ✅
d) list = //
14. Which of the following operators is used to calculate the remainder of a division in Python?
a) % ✅
b) //
c) /
d) **
15. Which method is used to add an element at the end of a list in Python?
a) append() ✅
b) add()
c) insert()
d) extend()
16. What will be the output of the following Python code: print(“Hello”[::-1])?
a) olleH ✅
b) Hello
c) H
d) None of the above
17. Which of the following is not a valid data type in Python?
a) List
b) Dictionary
c) String
d) Character ✅
18. What is the use of the continue statement in Python?
a) It breaks out of the loop
b) It skips the current iteration and continues with the next iteration ✅
c) It terminates the program
d) None of the above
19. Which of the following functions is used to create a new set in Python?
a) set() ✅
b) createSet()
c) makeSet()
d) newSet()
20. What is the correct syntax to define a function in Python?
a) function myFunction() {}
b) function myFunction[] {}
c) def myFunction(): ✅
d) None of the above
21. Which of the following is used to handle exceptions in Python?
a) try-catch
b) try-except ✅
c) exception-try
d) catch-try
22. What does the len() function return in Python?
a) The length of a string
b) The number of elements in a list or dictionary
c) The size of an object
d) All of the above ✅
23. What is the output of print(2 ** 3) in Python?
a) 5
b) 6
c) 8 ✅
d) 9
24. What is the output of the following Python code: print(type(5))?
a) int ✅
b) float
c) str
d) list
25. Which of the following is the correct syntax to import a module in Python?
a) import module
b) include module
c) import module()
d) import module as mod ✅
26. Which of the following statements about Python dictionaries is correct?
a) Keys in a dictionary must be unique ✅
b) Values in a dictionary must be unique
c) Dictionaries cannot store tuples
d) None of the above
27. Which of the following methods is used to remove an element from a set in Python?
a) delete()
b) remove() ✅
c) pop()
d) discard()
28. What is the result of the following Python expression: 4 > 3 and 2 < 1?
a) True
b) False ✅
c) SyntaxError
d) None of the above
29. Which of the following functions is used to convert a string into a list in Python?
a) list() ✅
b) split()
c) convert()
d) str_list()
30. How would you declare a variable x and assign it the value 10 in Python?
a) int x = 10
b) x = 10 ✅
c) variable x = 10
d) x := 10
31. What will be the output of the following code snippet? a = [1, 2] print(a * 3)
a) Error
b) [1, 2]
c) [1, 2, 1, 2]
d) [1, 2, 1, 2, 1, 2] ✅
32. What will be the output of the following code snippet? example = [“Sunday”, “Monday”, “Tuesday”, “Wednesday”]; del example[2] print(example)
a) ‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’
b) ‘Sunday’, ‘Monday’, ‘Wednesday’ ✅
c) ‘Monday’, ‘Tuesday’, ‘Wednesday’
d) ‘Sunday’, ‘Monday’, ‘Tuesday’
33. What will be the type of the variable sorted_numbers in the below code snippet? numbers = (4, 7, 19, 2, 89, 45, 72, 22) sorted_numbers = sorted(numbers) print(sorted_numbers)
a) List ✅
b) Tuple
c) String
d) Int
34. What will be the output of the following code snippet? s = {1, 2, 3, 3, 2, 4, 5, 5} print(s)
a) {1, 2, 3, 3, 2, 4, 5, 5}
b) [1, 2, 3, 4, 5] ✅
c) {1, 5}
d) None of these
35. Which of the following functions converts date to corresponding time in Python?
a) strptime() ✅
b) strftime()
c) Both A and B
d) None of these
36. As what datatype are the args stored, when passed into a function?
a) List
b) Tuple ✅
c) Dictionary
d) None of these
37. As what datatype are the kwargs stored, when passed into a function?
a) Lists
b) Tuples
c) Dictionary ✅
d) None of these
38. Which of the following blocks will always be executed whether an exception is encountered or not in a program?
a) try
b) except
c) finally ✅
d) None of these
39. What keyword is used in Python to raise exceptions?
a) raise ✅
b) try
c) goto
d) except
40. Which of the following are valid escape sequences in Python?
a) \n
b) \t
c) \
d) All of these ✅
41. Which of the following are valid string manipulation functions in Python?
a) count()
b) upper()
c) strip()
d) All of these ✅
42. Which of the following modules need to be imported to handle date-time computations in Python?
a) datetime ✅
b) date
c) time
d) timedate
43. In which language is Python written?
a) C++
b) C ✅
c) Java
d) None of these
44. In which year was the Python language developed?
a) 1995
b) 1972
c) 1981
d) 1989 ✅
45. In which year was the Python 3.0 version developed?
a) 2008 ✅
b) 2000
c) 2010
d) 2005
46. Which of the following statements is correct regarding the object-oriented programming concept in Python?
a) Class are real-world entities while objects are not real
b) Objects are real-world entities while classes are not real ✅
c) Both objects and classes are real-world entities
d) All of the above
47. What is the method inside the class in Python language?
a) Object
b) Function ✅
c) Attribute
d) Argument
48. Why does the name of local variables start with an underscore discouraged?
a) To identify the variable
b) It confuses the interpreter
c) It indicates a private variable of a class ✅
d) None of these
49. Which of the following is not a keyword in Python language?
a) val ✅
b) raise
c) try
d) with
50. Which one of the following has the same precedence level?
a) Division, Power, Multiplication, Addition and Subtraction
b) Division and Multiplication ✅
c) Subtraction and Division
d) Power and Division
51. Which one of the following has the highest precedence in the expression?
a) Division
b) Subtraction
c) Power
d) Parentheses ✅
52. Study the following function: import math abs(math.sqrt(36))
a) -6
b) 6
c) 6.0 ✅
d) Error
53. Python is a _____ object-oriented programming language?
a) Special purpose
b) General purpose ✅
c) Medium-level programming language
d) All of the above
54. Which of the following is the application areas of Python programming language?
a) Web Development
b) Game Development
c) Artificial Intelligence and Machine Learning
d) All of these ✅
55. Which of the following is the Numeric Data type?
a) int
b) float
c) complex
d) All of these ✅
56. List, tuple, and range are the _____ of Data types
a) Sequence Types ✅
b) Binary types
c) Boolean types
d) None of these
57. Which of the following is the logical operators in Python?
a) and
b) or
c) not
d) All of these ✅
58. What is the name of the operator ** in Python?
a) Exponentiation ✅
b) Modulus
c) Floor division
d) None of these
59. The % operator returns the ______.
a) Quotient
b) Divisor
c) Remainder ✅
d) None of these
60. Which of the following is the method of list?
a) append()
b) extend()
c) insert()
d) All of these ✅
61. Python Dictionary is used to store the data in a _____ format.
a) Key value pair ✅
b) Group value pair
c) Select value pair
d) None of these
62. Conditional statements are also known as _____ statements.
a) Decision making ✅
b) Array
c) List
d) None of these
63. Which of the following is not used as a conditional statement in Python?
a) switch ✅
b) if ….. else
c) elif
d) None of these
64. In a Python program, nested if statements denotes
a) if statement inside another if statement ✅
b) if statement outside the other if statement
c) Both A and B
d) None of these
65. In Python, the break and continue statements, together are called _____ statement.
a) Jump ✅
b) goto
c) compound
d) None of these
66. Loops are known as _____ in programming.
a) Control flow statements ✅
b) Conditional statements
c) Data structure statements
d) None of these
67. Which of the following is true about the while loop?
a) It continually executes the statements as long as the given condition is true ✅
b) It first checks the condition and then jumps into the instructions
c) The loop stops running when the condition becomes fail, and control will move to the next line of code
d) All of these
68. A function is a group of related statements which are designed specifically to perform a ______.
a) Write code
b) Specific task ✅
c) Create executable file
d) None of these
69. Among which of the following is a function that does not have any name?
a) Del function
b) Show function
c) Lambda function ✅
d) None of these
70. Which of the following is the key function used for file handling in Python?
a) open() and close()
b) read() and write()
c) append()
d) All of the mentioned above ✅
71. Which of the following is needed to open an existing file?
a) filename
b) mode
c) Both A and B ✅
d) None of these
72. The function file_object.close() is used to _____.
a) To open the existing file
b) To append in an opened file
c) To close an opened file ✅
d) None of these
73. The seek() method is used to ______.
a) Saves the file in secondary storage
b) Position the file object at a particular position in a file ✅
c) Deletes the file from secondary storage
d) None of these
74. Which of the following functions is used to create a file and write data?
a) append()
b) open() ✅
c) close()
d) None of these
75. The module Pickle is used to ____.
a) Serializing Python object structure ✅
b) De-serializing Python object structure
c) Both A and B
d) None of these
76. A text file contains only textual information consisting of _____.
a) Alphabets
b) Numbers
c) Special symbols
d) All of these ✅
77. Which of the following is the invalid variable?
a) 1st_string ✅
b) my_string_1
c) _
d) foo
78. The command used to start Python from the command prompt is _____.
a) execute python
b) python ✅
c) py
d) run python
79. Python is a/an _____
a) Programming language ✅
b) Web browser
c) Malware
d) Operating system
80. What does the name Python signify?
a) It is a snake
b) It is very difficult to use
c) Named after the British comedy group Monty Python ✅
d) All of these
81. What are the people who specialize in Python called?
a) Pythonic
b) Unpythonic
c) Monty Python
d) Pythoniasts ✅
82. All the keywords in Python are in ____
a) Lower case
b) Upper case
c) Capitalized
d) None of the above ✅
(Only True
, False
, and None
are capitalized; the rest are lowercase.)
83. What is the output of 33 == 33.0?
a) False
b) True ✅
c) 33
d) None of these
84. What symbol do you use to assess equality between two elements?
a) &&
b) =
c) == ✅
d) ||
85. What happens when you use the built-in function any() on a list?
a) The any() function will randomly return any item from the list
b) The any() function returns True if any item in the list evaluates True. Otherwise, it returns False ✅
c) The any() function takes as arguments the list to check inside, and the item to check for. If “any” of the items in the list match the item to check for, the function returns True
d) The any() function returns a Boolean value that answers the question “Are there any items in this list?”
86. Who developed the Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum ✅
d) Niene Stom
87. Which of the following is the correct extension of the Python file?
a) .python
b) .pl
c) .py ✅
d) .p
88. Which keyword is used for functions in Python language?
a) Function
b) def ✅
c) Fun
d) Define
89. Which of the following functions is a built-in function in Python?
a) factorial()
b) print() ✅
c) seed()
d) sqrt()
90. Which type of programming does Python support?
a) object-oriented programming
b) structured programming
c) functional programming
d) all of the above ✅
91. Which of the following is used to define a block of code in Python language?
a) Indentation ✅
b) Key
c) Brackets
d) All of the above
92. Which of the following character is used to give single-line comments in Python?
a) //
b) # ✅
c) !
d) /*
93. What arithmetic operators cannot be used with strings in Python?
a) *
b) –
c) +
d) All of the mentioned ✅
94. What will be the output of the following Python code?print("abc. DEF".capitalize())
a) Abc. Def
b) abc. Def
c) Abc. Def ✅
d) ABC. DEF
95. 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)
a) error
b) 0 1 2 0
c) 0 1 2 ✅
d) none of these
96. Which of the following is used to create an empty set in Python?
a) set() ✅
b) {}
c) []
d) ()
97. Which of the following is the method to add an element to the set in Python?
a) add() ✅
b) insert()
c) append()
d) append_item()
98. What will be the output of the following code snippet?
a = "Hello"
b = "World"
print(a + b)
a) Hello World
b) HelloWorld ✅
c) Hello+World
d) Error
99. What is the purpose of the pass statement in Python?
a) To do nothing ✅
b) To skip the rest of the current function
c) To pass control to the next function
d) To return a value
100. Which of the following will open a file in read mode in Python?
a) open(“file.txt”, “r”) ✅
b) open(“file.txt”, “w”)
c) open(“file.txt”, “rw”)
d) open(“file.txt”, “rb”)
101. Which of the following is used to get the type of an object in Python?
a) type() ✅
b) class()
c) object()
d) type_of()
102. Which of the following will convert a string to lowercase in Python?
a) toLowerCase()
b) lower() ✅
c) lowercase()
d) lower_case()
103. What is the return type of the input() function in Python?
a) String ✅
b) Integer
c) Float
d) Boolean
104. Which of the following is used to convert an integer to string in Python?
a) to_str()
b) str() ✅
c) int()
d) string()
105. Which of the following is used to declare an anonymous function in Python?
a) Lambda function ✅
b) Anonymous function
c) Define function
d) Function()
106. What does the assert statement do in Python?
a) Checks if a condition is true and raises an exception if false ✅
b) Checks if a value is an integer
c) Returns a Boolean value
d) Asserts an error message
107. Which of the following is used to find the length of a list in Python?
a) len() ✅
b) size()
c) count()
d) length()
108. What is the output of the following Python code?
x = 5
y = 10
print(x < y)
a) True ✅
b) False
c) Error
d) None
109. What is the default return value of a Python function that does not explicitly return anything?
a) None ✅
b) 0
c) False
d) Error
110. Which of the following is the correct way to declare a global variable inside a function in Python?
a) global x = 5
b) global x
c) x = global 5
d) global variable x = 5
111. How can you add a comment in a Python script?
a) // This is a comment
b) # This is a comment ✅
c) /* This is a comment */
d) — This is a comment
112. What will the following Python code output?
x = 3
x = x + 1
print(x)
a) 4 ✅
b) 3
c) Error
d) None
113. Which of the following is used to remove an item from a list in Python by its value?
a) remove() ✅
b) pop()
c) delete()
d) clear()
114. Which of the following is the correct way to define a function in Python?
a) def function_name(): ✅
b) function function_name():
c) func function_name():
d) function: function_name()
115. Which of the following is used to remove all items from a list in Python?
a) clear() ✅
b) delete()
c) pop()
d) remove()
116. What will be the output of the following Python code?
a = [1, 2, 3, 4]
a[2] = 5
print(a)
a) [1, 2, 5, 4] ✅
b) [1, 2, 3, 4, 5]
c) [1, 2, 4, 5]
d) Error
117. Which of the following is not a valid way to create a list in Python?
a) [1, 2, 3]
b) list(1, 2, 3)
c) list(1, 2, 3) ✅
d) list([1, 2, 3])
118. Which of the following will return the highest value in a list?
a) max() ✅
b) high()
c) largest()
d) get_max()
119. What does the zip() function do in Python?
a) Combines two lists into one list of tuples ✅
b) Compresses a file
c) Zips a string
d) None of the above
120. How do you create a tuple in Python?
a) tuple()
b) (1, 2, 3) ✅
c) [1, 2, 3]
d) {1, 2, 3}
121. Which of the following statements is correct about tuples in Python?
a) Tuples are mutable
b) Tuples are immutable ✅
c) Tuples cannot store elements of different data types
d) None of the above
122. Which of the following will return the number of occurrences of an item in a list?
a) count() ✅
b) occurrences()
c) find()
d) search()
123. Which of the following is a Python built-in function to get the remainder of a division operation?
a) mod()
b) % ✅
c) divide()
d) remainder()
124. What is the result of 2 ** 3 in Python?
a) 6
b) 8 ✅
c) 9
d) 5
125. Which of the following is the correct way to use the map() function in Python?
a) map(function, iterable) ✅
b) map(iterable, function)
c) map(function)
d) map(iterable)
126. Which of the following is used to create a new directory in Python?
a) makeDir()
b) os.mkdir() ✅
c) mkdir()
d) None of the above
127. What will be the output of the following code?
x = "Python"
print(x[0:3])
a) Pyt ✅
b) Py
c) Pyth
d) Python
128. What is the correct way to handle exceptions in Python?
a) try…except ✅
b) catch…throw
c) try…catch
d) None of the above
129. How do you open a file for writing in Python?
a) open(“file.txt”, “w”) ✅
b) open(“file.txt”, “r”)
c) open(“file.txt”, “a”)
d) open(“file.txt”, “x”)
130. Which function is used to get the current date and time in Python?
a) current_time()
b) datetime.now() ✅
c) now()
d) get_time()
131. What does the enumerate() function do in Python?
a) Returns a list of enumerated elements from a sequence ✅
b) Returns the length of a list
c) Creates an empty dictionary
d) None of the above
132. How can you check if a key exists in a Python dictionary?
a) key in dictionary ✅
b) dictionary.has_key()
c) exists(key)
d) None of the above
133. What will be the output of the following code snippet?
print("Python"[-1])
a) n ✅
b) o
c) P
d) Error
134. Which of the following is used to check the data type of a variable in Python?
a) type() ✅
b) datatype()
c) class()
d) data_type()
135. Which of the following is true about Python functions?
a) Python functions do not have return values
b) Python functions must always return a value
c) Python functions can return multiple values ✅
d) None of the above