Python MCQs Test 4 Fill in your details and start your exam now! NameEmailPhone Number 1 / 20 What is the purpose of the break statement in a loop? Exits the loop entirely Skips the current iteration and continues with the next one Pauses the loop temporarily None of the above 2 / 20 What does the reverse() method do in Python lists? Reverses the order of elements in the list Removes the last element of the list Adds an element to the end of the list Returns a reversed version of the list 3 / 20 What is the output of the following code? \npython\nprint("python".upper()) python PYTHON Python pytHon 4 / 20 Which of the following is the correct way to open a file named example.txt in Python for reading and writing? open("example.txt", "rw") open("example.txt", "r+") open("example.txt", "w+") open("example.txt", "readwrite") 5 / 20 What is the output of the following code? \npython\nx = [1, 2, 3]\nprint(x.pop()) 1 2 3 None 6 / 20 What does the any() function do in Python? Checks if any element in an iterable is True Checks if all elements in an iterable are True Checks if an iterable is empty Converts an iterable to a boolean value 7 / 20 What is the output of the following code? \npython\nprint("hello".index("l")) 2 3 4 5 8 / 20 Which of the following is NOT a valid way to define a function in Python? function my_function(): def my_function(): create my_function(): func my_function(): 9 / 20 What does the clear() method do in Python dictionaries? Removes all items from the dictionary Returns a shallow copy of the dictionary Returns the value associated with a specified key Updates the dictionary with elements from another dictionary 10 / 20 What is the output of the following code? \npython\nprint(5 != 5) True False Error None 11 / 20 What is the purpose of the pass statement in Python? It is a null operation; nothing happens when it is executed It is used to break out of a loop It is used to skip the current iteration of a loop It is used to define an empty function or class 12 / 20 What does the update() method do in Python dictionaries? Updates the dictionary with elements from another dictionary Adds a new key-value pair to the dictionary Removes a key-value pair from the dictionary Returns the value associated with a key 13 / 20 What is the output of the following code? \npython\nprint("python".capitalize()) Python python PYTHON pytHon 14 / 20 Which of the following is the correct way to open a file named example.txt in Python for appending? open("example.txt", "a") open("example.txt", "append") open("example.txt", "r+") append("example.txt") 15 / 20 What is the output of the following code? \npython\nx = [1, 2, 3]\nprint(x[1:2]) [1, 2, 3] [2] [1, 2] [2, 3] 16 / 20 What does the isinstance() function do in Python? Checks if an object is an instance of a specified class Checks if two objects are the same Checks if an object is empty Converts a string to lowercase 17 / 20 What is the output of the following code? \npython\nx = 10\ny = 5\nprint(x // y) 2 2.0 3 3.0 18 / 20 Which of the following is NOT a valid way to iterate over a dictionary in Python? for key in my_dict: for value in my_dict.values(): for item in my_dict.items(): for index in range(len(my_dict)): 19 / 20 What does the format() method do in Python? Formats a string with placeholders replaced by the specified values Returns the length of a string Converts a string to lowercase Splits a string into a list 20 / 20 What is the purpose of the finally block in a try-except statement in Python? It is always executed regardless of whether an exception occurs or not It is executed if an exception occurs It is executed if no exception occurs It is executed before the try block Your score isThe average score is 79% 0% Restart Your Test