







































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








































































Question 1. Which of the following is a primary characteristic of an interpreted language like Python? A) The entire source code is translated into machine code before execution B) Code is executed line-by-line by an interpreter C) It requires a separate linking phase to create an executable file D) It is generally faster than compiled languages Answer: B Explanation: Python is an interpreted language, meaning the interpreter reads and executes the code instruction by instruction, rather than compiling the whole program into machine code first. Question 2. What is the result of the following expression: 7 // 2? A) 3. B) 3. C) 3 D) 4 Answer: C Explanation: The // operator performs floor division, which divides the numbers and rounds down to the nearest whole integer. Question 3. In Python, which of the following is an invalid variable name? A) my_var B) var C) 2_var D) MyVar Answer: C Explanation: Variable names in Python cannot start with a digit. They must start with a letter or an underscore.
Question 4. Which function is used to get the unique identifier of an object in memory? A) type() B) id() C) hex() D) loc() Answer: B Explanation: The id() function returns the "identity" of an object, which is an integer guaranteed to be unique and constant for this object during its lifetime. Question 5. What is the output of the code: print(2 ** 3 ** 2)? A) 64 B) 512 C) 18 D) 81 Answer: B Explanation: The exponentiation operator ** has right-to-left associativity. Therefore, 3 ** 2 is calculated first (9), and then 2 ** 9 results in 512. Question 6. Which keyword is used to skip the current iteration of a loop and move to the next one? A) break B) skip C) continue D) pass Answer: C Explanation: The continue statement stops the current iteration of a loop and returns control to the loop header to start the next iteration.
Question 10. Which exception is raised when trying to access a key that does not exist in a dictionary? A) ValueError B) IndexError C) KeyError D) NameError Answer: C Explanation: A KeyError is raised when a dictionary key is not found in the set of existing keys. Question 11. What is the value of the expression: 10 % 3? A) 3 B) 1 C) 0. D) 10 Answer: B Explanation: The modulo operator % returns the remainder of the division. 10 divided by 3 is 3 with a remainder of 1. Question 12. Which method is used to add an element to the end of a list? A) add() B) push() C) append() D) insert() Answer: C Explanation: The append() method adds a single item to the end of an existing list.
Question 13. What does the following code snippet print? x = "Python"; print(x[1:4]) A) Pyt B) yth C) ytho D) ythn Answer: B Explanation: Slicing [1:4] starts at index 1 ('y') and goes up to, but does not include, index 4 ('o'). Question 14. Which of the following is the Boolean "OR" operator in Python? A) || B) or C) | D) OR Answer: B Explanation: Python uses the English word 'or' as its logical OR operator. Question 15. What will be the result of print(type(1 / 1))? A) B) C) D) Answer: B Explanation: In Python 3, the division operator / always returns a float, even if the result is a whole number. Question 16. How do you insert a single-line comment in Python?
C) To skip the next line of code D) To terminate the entire program Answer: B Explanation: The break statement is used to terminate the loop in which it is currently residing. Question 20. Which of the following represents a hexadecimal literal? A) 0hFF B) 0xFG C) 0xFF D) xFF Answer: C Explanation: Hexadecimal literals in Python start with the prefix 0x or 0X followed by digits 0-9 and letters A-F. **Question 21. What will be the output of: print(len(["apple", "banana", "cherry"]))? ** A) 3 B) 20 C) 1 D) 6 Answer: A Explanation: The len() function returns the number of items in a sequence (in this case, 3 strings in a list). Question 22. What happens if a variable is defined inside a function? A) It can be accessed anywhere in the script B) It is a global variable
C) It has local scope and can only be accessed within that function D) It is automatically deleted after the first use Answer: C Explanation: Variables defined inside a function are local to that function and cannot be accessed from outside unless declared global. Question 23. What is the result of: bool("")? A) True B) False C) None D) Error Answer: B Explanation: In Python, an empty string is considered "falsy," so converting it to a boolean results in False. Question 24. Which function allows a user to provide text input? A) read() B) get() C) input() D) scan() Answer: C Explanation: The input() function reads a line from input, converts it to a string, and returns it. Question 25. Which range() function call will generate the sequence 0, 1, 2? A) range(3) B) range(0, 3, 1) C) range(1, 3)
D) Error Answer: C Explanation: float("1.5") converts the string to 1.5, and 1.5 * 2 results in 3.0 (a float). Question 29. Which method is used to remove and return the last item in a list? A) delete() B) remove() C) pop() D) discard() Answer: C Explanation: pop() without arguments removes and returns the last item in the list. Question 30. How do you define a dictionary in Python? A) my_dict = [] B) my_dict = () C) my_dict = {} D) my_dict = "" Answer: C Explanation: Curly braces {} are used to define a dictionary literal. Question 31. What is the output of: print("Python"[::-1])? A) P B) nohtyP C) Python D) ythonP Answer: B
Explanation: The slice [::-1] reverses the string. Question 32. Which of the following is not a Python keyword? A) eval B) while C) yield D) import Answer: A Explanation: 'eval' is a built-in function, not a reserved keyword. 'while', 'yield', and 'import' are keywords. Question 33. What is the default return value of a function that does not have a return statement? A) 0 B) False C) None D) "" Answer: C Explanation: If no return statement is specified, Python functions implicitly return None. Question 34. What is the result of: 2 + 3 * 4? A) 20 B) 14 C) 12 D) 24 Answer: B
Question 38. What will be the output of: print(list(range(1, 10, 3)))? A) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] B) [1, 4, 7] C) [1, 4, 7, 10] D) [3, 6, 9] Answer: B Explanation: range(1, 10, 3) starts at 1, increments by 3, and stops before 10. The values are 1, 4, 7. Question 39. Which escape character is used to represent a newline? A) \t B) \n C) \r D) \ Answer: B Explanation: \n is the escape sequence for a newline character. Question 40. What is the output of: print(not(5 > 2))? A) True B) False C) 5 D) 2 Answer: B Explanation: 5 > 2 is True. The 'not' operator negates it, making the result False. Question 41. Which list method sorts the list in place?
A) sorted() B) sort() C) order() D) arrange() Answer: B Explanation: sort() is a list method that modifies the original list in place. sorted() is a function that returns a new sorted list. Question 42. What is the output of: print(type(None))? A) B) C) D) Answer: B Explanation: The None object belongs to the class NoneType. Question 43. Which of the following creates a tuple? A) x = [1, 2] B) x = {1, 2} C) x = (1, 2) D) x = 1, 2 Answer: C Explanation: Parentheses are typically used to define tuples, though the commas are what actually create the tuple (Option D is also technically a tuple, but C is the standard literal form). Question 44. What is the result of: "Hello".replace("l", "w")? A) Hewwo
D) include module.function Answer: B Explanation: The "from module import function" syntax allows you to import specific items from a module into the local namespace. Question 48. What is the output of: print(bool(0))? A) True B) False C) None D) 0 Answer: B Explanation: In Python, the integer 0 is considered False. Question 49. Which of the following is used to handle any exception that might occur? A) except Error: B) except Exception: C) except: D) catch: Answer: C Explanation: A bare except: block catches all exceptions (though catching Exception is generally preferred for better practice). Question 50. What is the result of: "Python" * 2? A) "PythonPython" B) "Python 2" C) "Python" D) Error
Answer: A Explanation: The * operator used with a string and an integer performs string replication. Question 51. Which of the following is used to define a block of code in Python? A) Curly braces B) Parentheses C) Indentation D) Quotation marks Answer: C Explanation: Python uses whitespace indentation to define the scope and structure of code blocks. Question 52. What is the output of: print(10 // 3)? A) 3. B) 3 C) 4 D) 1 Answer: B Explanation: The // operator is floor division, which returns the largest integer less than or equal to the division result. Question 53. Which of the following is NOT a valid numeric literal in Python? A) 1_ B) 3.14j C) 0b D) 0xABC Answer: C
Question 57. Which method can be used to split a string into a list? A) divide() B) split() C) slice() D) break() Answer: B Explanation: The split() method breaks a string into a list of substrings based on a delimiter (default is whitespace). Question 58. What is the output of: print(round(4.5))? A) 4 B) 5 C) 4. D) 5. Answer: A Explanation: Python 3 rounds to the nearest even number when a value is exactly .5. This is known as "banker's rounding." Question 59. Which operator has the lowest precedence? A) ** B) * C) + D) or Answer: D Explanation: Logical operators like 'or' have lower precedence than arithmetic operators.
Question 60. What is the result of: "apple" in ["apple", "orange"]? A) True B) False C) Error D) apple Answer: A Explanation: The 'in' operator checks for membership. Since "apple" is in the list, it returns True. Question 61. Which function is used to convert an integer to a string? A) str() B) string() C) int_to_str() D) char() Answer: A Explanation: The str() function converts the specified value into a string. Question 62. What will be the output of the following code? x = [1, 2, 3]; y = x; y.append(4); print(x) A) [1, 2, 3] B) [1, 2, 3, 4] C) [4] D) Error Answer: B Explanation: Lists are mutable. y = x creates a reference to the same list. Modifying y also modifies x.