#1
What does the 'print' function do in Python?
Reads user input from the keyboard
Displays output on the screen
Executes a loop
Defines a new function
#2
Which of the following is NOT a valid variable name in Python?
my_variable
_variable1
1variable
variable_2
#3
What is the output of the following code?
x = [1, 2, 3]
print(x.pop())
#4
Which of the following is used to handle exceptions in Python?
try-except
if-else
for loop
while loop
#5
What is the output of the following code?
x = 'hello'
print(x[::-1])
olleh
hello
eh
None of the above
#6
What is the output of the following code?
x = [1, 2, 3]
print(x.append(4))
[1, 2, 3, 4]
None
4
TypeError: 'NoneType' object is not iterable
#7
What is the output of the following code?
x = 5
y = 2
print(x ** y)
#8
What is the purpose of 'pass' statement in Python?
To stop the execution of a loop
To raise an exception
To define an empty code block
To assign a value to a variable
#9
What does the 'self' keyword refer to in Python?
Refers to the current instance of a class
Refers to the parent class
Refers to a built-in Python function
Refers to the module where the code is defined
#10
What does the 'global' keyword do in Python?
Declares a variable as global within a function
Imports a module globally
Defines a class globally
Specifies a global scope for a variable
#11
What does the 'enumerate' function do in Python?
Returns the sum of elements in a list
Returns an iterator of tuples containing indices and elements
Converts a list into a dictionary
Applies a function to every element in a list
#12
What is the purpose of the 'finally' block in a try-except statement?
To handle exceptions
To execute code regardless of whether an exception occurred or not
To specify alternative code paths
To define custom exceptions
#13
What does the 'join' method do in Python?
Splits a string into a list
Joins elements of a list into a single string
Finds the maximum element in a list
Reverses a list
#14
What is the purpose of 'lambda' functions in Python?
To create anonymous functions
To declare global variables
To define class methods
To iterate over a list
#15
What does the 'map' function do in Python?
Applies a function to every element in an iterable
Filters elements from an iterable
Sorts elements in an iterable
Combines elements of iterables into a single iterable
#16
What is the purpose of the 'yield' keyword in Python?
To terminate a loop
To return a value from a generator function
To raise an exception
To define a class method
#17
What is the purpose of the 'staticmethod' decorator in Python?
To define a method that can be called on an instance of a class
To define a method that can only be called on the class itself, not on its instances
To define a method that can access and modify class attributes
To define a method that automatically receives a reference to the instance as the first parameter