Python MCQs Test 2 Fill in your details and start your exam now! NameEmailPhone Number 1 / 20 What does the extend() method do in Python? Adds elements of another list to the end of the current list Removes elements from a list Returns a reversed version of the list Sorts the elements of the list 2 / 20 Which of the following is NOT a valid way to declare a variable in Python? my_variable = 5 5 = my_variable myVariable = 5 _my_variable = 5 3 / 20 What is the output of the following code? \nprint("Hello".lower()) hello Hello HELLO hELLO 4 / 20 How do you check the length of a list named my_list in Python? length(my_list) size(my_list) len(my_list) count(my_list) 5 / 20 What is the output of the following code? \nprint(10 != 10) True False Error None 6 / 20 What is the result of the expression 2 * 3 ** 2 in Python? 18 12 27 9 7 / 20 What does the range() function in Python return? A list of numbers A generator object A tuple of numbers A dictionary of numbers 8 / 20 Which of the following is the correct way to open a file in Python, ensuring it gets closed properly afterward? file = open("example.txt") with open("example.txt") as file: file = open("example.txt", "w") file = open("example.txt", "r") 9 / 20 What does the pop() method do in Python? Adds an element to the end of a list Removes the last element of a list Removes the first element of a list Returns the index of a specified element in a list 10 / 20 What is the output of the following code? \npython\nx = 5\ny = 2\nprint(x % y) 2.5 2 2.0 1 11 / 20 What is the purpose of the continue statement in a loop? Skips the current iteration and continues with the next one Exits the loop entirely Pauses the loop temporarily Restarts the loop from the beginning 12 / 20 What is the output of the following code? \nprint("Python".upper()) python PYTHON Python pytHon 13 / 20 How do you comment multiple lines in Python? // This is a comment /* This is a comment */ ''' This is a comment ''' # This is a comment 14 / 20 What is the output of the following code? \nprint(8 < 6) True False Error None 15 / 20 Which keyword is used to define a function in Python? func define function def 16 / 20 What is the output of the following code? \nprint("Python" * 3) Python PythonPython PythonPythonPython Pyytthhoonn 17 / 20 What does the __init__ method do in Python? Initializes a class object Initializes a list Initializes a loop Initializes a dictionary 18 / 20 What is the result of the expression 2 == "2" in Python? True False Error None 19 / 20 What does the append() method do in Python? Adds an element to the end of a list Removes an element from a list Returns the index of a specified element in a list Reverses the elements of a list 20 / 20 Which of the following statements is true about Python? Python is a high-level programming language Python is a low-level programming language Python is a markup language Python is a hardware description language Your score isThe average score is 75% 0% Restart Your Test