Python MCQs Test 1 Python MCQS Test 1 1 / 20 What is the output of the following code? \nprint(7 // 3) 2 2.333 2.0 3 2 / 20 How do you create a function in Python? def my_function(): function my_function(): create my_function(): func my_function(): 3 / 20 What does the sorted() function return in Python? A sorted list A sorted tuple A sorted set A sorted dictionary 4 / 20 What is the output of the following code? \nprint("hello".capitalize()) hello HELLO Hello hELLO 5 / 20 Which of the following is NOT a valid comparison operator in Python? > = <= != 6 / 20 What is the result of the expression True and False in Python? True False None Error 7 / 20 What is the purpose of the pass statement in Python? To pause the execution of a loop To define an empty function or class To skip the current iteration of a loop To break out of a loop 8 / 20 How do you open a file named example.txt in Python for reading? open("example.txt", "r") read("example.txt") fopen("example.txt", "read") open("example.txt") 9 / 20 What is the output of the following code? \nprint("Python"[::-1]) Python nohtyP p n 10 / 20 What does the len() function do in Python? Returns the length of a list, tuple, or string Returns the largest element of a list Returns the smallest element of a list Returns the sum of all elements in a list 11 / 20 What is the output of the following code? \nprint(10 % 3) 1 2 3 0 12 / 20 How do you import a module named mymodule in Python? import mymodule include mymodule import module:mymodule from mymodule import 13 / 20 What does the strip() method do in Python? Removes leading and trailing whitespaces Removes all occurrences of a specified character Splits a string into a list Converts the string to uppercase 14 / 20 Which of the following is NOT a valid way to comment in Python? // This is a comment # This is a comment ''' This is a comment ''' /* This is a comment */ 15 / 20 What is the output of the following code? \nprint("Hello" + "World") HelloWorld Hello World Hello+World Error 16 / 20 What does the break statement do 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 17 / 20 Which of the following data types is mutable in Python? Tuple List Set String 18 / 20 What is the result of the expression 3 ** 2 in Python? 6 9 27 81 19 / 20 Which of the following is NOT a valid variable name in Python? _my_var myVar 1stVar my_var_2 20 / 20 What is the output of the following code? \nprint(2 + 2 * 3 - 2 / 2) 5 6 7 8 Your score isThe average score is 0% 0% Restart quiz