





















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!






















1. What is the correct file extension for Python files? A. .pt B. .py C. .pyt D. .python Answer: B Python source files use .py extension. 2. Which keyword is used to define a function in Python? A. func B. define C. def D. function Answer: C def is the standard keyword for function definition. 3. What is the output of print(2 ** 3)? A. 6 B. 8 C. 9 D. 5 Answer: B Exponentiation 2³ equals 8. 4. Which of the following is a mutable data type?
A. tuple B. string C. list D. int Answer: C Lists can be modified after creation.
5. What does len("Python") return? A. 5 B. 6 C. 7 D. Error Answer: B The string "Python" has 6 characters. 6. Which keyword is used for loops in Python? A. loop B. for C. iterate D. repeat Answer: B for is used for iteration. 7. What is the output of type(10)? A. int B. float C. str D. number
Answer: B // returns quotient without remainder.
12. What is the output of 10 % 3? A. 3 B. 1 C. 0 D. 2 Answer: B Remainder of 10 divided by 3 is 1. 13. Which keyword is used to handle exceptions? A. catch B. except C. error D. tryonly Answer: B except handles exceptions. 14. What does the "break" statement do? A. Skips iteration B. Exits loop C. Restarts loop D. Pauses program
Answer: B break terminates loop execution.
15. Which collection type stores key-value pairs? A. list B. tuple C. dictionary D. set Answer: C Dictionaries use key-value mapping. 16. Which function converts string to integer? A. str() B. int() C. float() D. chr() Answer: B int() converts values to integers. 17. What is the output of bool(0)? A. True B. False C. 0 D. Error Answer: B 0 evaluates to False. 18. Which module is used for math operations?
Answer: D set() explicitly creates a set.
22. Which keyword is used to create a class? A. object B. class C. def D. struct Answer: B class defines object blueprint. 23. What is inheritance? A. Copying variables B. Using loops C. Acquiring properties from another class D. Deleting objects Answer: C Inheritance allows class reuse. 24. What does pop() do in a list? A. Adds element B. Removes last element C. Sorts list D. Clears list Answer: B pop removes and returns element. 25. What is correct boolean value?
C. True D. None Answer: C Python uses True/False.
26. What is output of 3 == 3? A. True B. False C. 3 D. Error Answer: A Comparison is true. 27. Which loop runs at least once? A. for B. while C. do-while (Python has none) D. None Answer: D Python has no do-while loop. 28. Which keyword defines null value? A. null B. void C. none D. None
A. size() B. len() C. length() D. count() Answer: B len() gives size of object.
33. Which is correct dictionary syntax? A. [a:1] B. (a:1) C. {a:1} D. Answer: C Dictionaries use curly braces. 34. What is output of 5/2? A. 2 B. 2. C. 3 D. 2. Answer: B Division returns float. 35. Which operator checks equality? A. = B. == C. := D. !=
Answer: B == compares values.
36. What is lambda? A. Loop B. Function C. Anonymous function D. Variable Answer: C Lambda defines small anonymous functions. 37. What does sorted() do? A. Reverses list B. Sorts elements C. Deletes elements D. Adds elements Answer: B sorted returns ordered sequence. 38. What is recursion? A. Looping B. Function calling itself C. Variable reuse D. Class inheritance Answer: B Recursion is self-calling function. 39. Which keyword exits function?
43. What is output of print(10 > 5 and 3 < 2)? A. True B. False C. None D. Error Answer: B Both conditions must be true for AND. 44. Which keyword is used to define a generator? A. yield B. return C. gen D. iterate Answer: A yield creates a generator function. 45. What is a Python module? A. A loop B. A file containing Python code C. A variable D. A class only Answer: B Modules are reusable Python files. 46. Which function removes whitespace? A. strip() B. trim()
C. clean() D. cut() Answer: A strip removes leading/trailing spaces.
47. What does dict.get(key) do? A. Deletes key B. Returns value safely C. Adds key D. Sorts dictionary Answer: B get avoids KeyError if missing. 48. Which data type stores unique elements? A. list B. tuple C. set D. dictionary Answer: C Sets store unique values only. 49. What is output of len([1,2,3])? A. 2 B. 3 C. 4 D. Error Answer: B List has 3 elements.
C. Error D. "10" Answer: B String converted to float.
54. Which keyword is used for conditional statements? A. switch B. if C. case D. when Answer: B if is used for conditions. 55. What is output of bool("")? A. True B. False C. Error D. None Answer: B Empty string is False. 56. Which method converts string to lowercase? A. lower() B. down() C. small() D. casefolded() Answer: A lower() converts text to lowercase.
57. What is object in Python? A. Function B. Instance of a class C. Loop D. Module Answer: B Objects are class instances. 58. What does init do? A. Deletes object B. Initializes object C. Imports module D. Ends program Answer: B Constructor method for initialization. 59. What is output of 4//2? A. 2 B. 2. C. 1 D. Error Answer: A Floor division returns integer. 60. Which keyword is used to inherit a class? A. extends B. inherits
64. What is output of 2 == "2"? A. True B. False C. Error D. None Answer: B Different types are not equal. 65. Which function returns absolute value? A. abs() B. absolute() C. mod() D. math.abs() only Answer: A abs returns positive value. 66. What is slicing in Python? A. Deleting list B. Accessing parts of sequence C. Looping D. Sorting Answer: B Slicing extracts portions of data. 67. What is output of "Python"[0]? A. y B. P
C. t D. Error Answer: B Indexing starts at 0.
68. Which operator means NOT equal? A. <> B. != C. == D. not Answer: B != checks inequality. 69. What does pass statement do? A. Stops program B. Does nothing C. Skips loop D. Raises error Answer: B pass is placeholder. 70. What is output of range(3)? A. 1,2, B. 0,1, C. 0,1,2, D. Error Answer: B range starts from 0.