























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The PrepIQ Python Certifications Ultimate Exam provides comprehensive preparation for Python programming certification pathways. Topics include Python fundamentals, object-oriented programming, data structures, file handling, automation, web development, APIs, testing, debugging, and scripting techniques. Candidates gain practical coding expertise applicable across software development, data science, and automation careers.
Typology: Exams
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































Question 1. Which of the following best describes the difference between an interpreter and a compiler in Python? A) An interpreter translates source code to machine code at runtime, while a compiler does it before execution. B) A compiler translates source code to bytecode, while an interpreter executes bytecode directly. C) Python uses only a compiler; there is no interpreter. D) An interpreter only works with compiled languages. Answer: A Explanation: Python’s standard implementation (CPython) first compiles source code to bytecode, then an interpreter executes that bytecode at runtime. The key distinction is that interpretation happens during execution, whereas compilation produces a standalone executable beforehand.
Question 2. What is the result of the expression 7 // 3 in Python? A) 2. B) 2 C) 3 D) 2. Answer: B Explanation: // is the floor-division operator; it returns the integer quotient of the division, discarding the remainder.
Question 3. Which bitwise operator in Python inverts all bits of an integer? A) & B) | C) ~
Answer: C Explanation: The unary ~ operator performs bitwise NOT, flipping each bit of the operand.
Question 4. In the statement print("Hello", "World", sep="-", end="!"), what will be printed? A) Hello-World! B) Hello World! C) Hello-World D) Hello World Answer: A Explanation: sep replaces the default space between arguments with -, and end replaces the newline with !.
Question 5. Which of the following is a valid Boolean literal in Python? A) Truee B) FALSE C) True D) bool Answer: C Explanation: The correct Boolean literals are True and False (case-sensitive).
B) To modify a variable defined in the global scope. C) To import a module globally. D) To declare a constant. Answer: B Explanation: global tells Python that assignments to the named variable should affect the variable in the module’s global namespace, not a new local one.
Question 9. Which of the following statements correctly reads a line from a file named data.txt? A) line = open('data.txt').readline() B) with open('data.txt', 'r') as f: line = f.readline() C) line = file('data.txt').read() D) with open('data.txt') as f: line = f.readline() Answer: B Explanation: Using a with statement ensures the file is properly closed; readline() reads a single line.
Question 10. In Python, which of the following is true about tuples? A) They are mutable sequences. B) They can be used as dictionary keys because they are hashable. C) They support item assignment. D) They are always empty. Answer: B Explanation: Tuples are immutable and therefore hashable, allowing them to be used as dictionary keys.
Question 11. What does the *args syntax allow in a function definition? A) Passing a variable number of positional arguments as a tuple. B) Passing a variable number of keyword arguments as a dictionary. C) Enforcing exactly three arguments. D) Declaring a function as static. Answer: A Explanation: *args collects any extra positional arguments into a tuple.
Question 12. Which of the following statements will raise a ZeroDivisionError? A) int("0") / 5 B) 5 / 0.0 C) 5 // 0 D) 5 % 0 Answer: C Explanation: Floor division (//) by zero triggers ZeroDivisionError. Division by a floating-point zero also raises the same error, but option C is the most direct.
Question 13. Given d = {'a': 1, 'b': 2}, what does d.get('c', 0) return? A) None B) 0 C) KeyError D) 'c' Answer: B
Question 16. Which of the following is the correct way to import only the sqrt function from the math module? A) import math.sqrt B) from math import sqrt C) import sqrt from math D) import math as sqrt Answer: B Explanation: from math import sqrt imports the specific function directly into the namespace.
Question 17. What does the __init__.py file indicate in a directory? A) That the directory is a Python package. B) That the directory contains only compiled modules. C) That the directory is a virtual environment. D) That the directory should be ignored by the interpreter. Answer: A Explanation: Presence of __init__.py tells Python that the folder is a package, enabling imports from it.
Question 18. Which of the following statements creates a list comprehension that generates squares of numbers from 0 to 4? A) [x**2 for x in range(5)] B) {x**2 for x in range(5)}
C) (x**2 for x in range(5)) D) list(x**2 for x in range(5)) Answer: A Explanation: Square brackets produce a list; the expression inside computes the square.
Question 19. What is the output of the following code?
s = "Python" print(s[:: -1])A) nohtyP B) Python C) Pyth D) noyhtP Answer: A Explanation: The slice [::-1] reverses the string.
Question 20. Which of the following will correctly catch both ValueError and TypeError in a single except clause? A) except (ValueError, TypeError): B) except ValueError or TypeError: C) except ValueError, TypeError: D) except [ValueError, TypeError]: Answer: A
B) True if obj is an instance of cls or a subclass thereof. C) True if obj can be cast to cls. D) The class name of obj. Answer: B Explanation: isinstance checks inheritance, returning True for instances of the class or any subclass.
Question 24. Which of the following will correctly open a file for appending text without truncating existing content? A) open('log.txt', 'w') B) open('log.txt', 'a') C) open('log.txt', 'r+') D) open('log.txt', 'x') Answer: B Explanation: Mode 'a' opens the file for appending; data is written at the end and the file is created if it does not exist.
Question 25. What does the datetime.timedelta(days=5) object represent? A) A specific date 5 days from epoch. B) A duration of 5 days. C) The current time plus 5 days. D) A timezone offset of 5 days. Answer: B Explanation: timedelta objects represent time differences; days=5 means a 5 - day duration.
Question 26. Which of the following statements about the requests library is true? A) requests.get() returns a dictionary. B) requests.post() can send JSON data using the json= parameter. C) requests is part of the Python standard library. D) requests.delete() removes a local file. Answer: B Explanation: The json= argument automatically serializes a Python object to JSON and sets the appropriate header.
Question 27. What will be the output of the following code?
a = [1, 2, 3] b = a b.append(4) print(a)A) [1, 2, 3] B) [1, 2, 3, 4] C) [[1, 2, 3], 4] D) Error Answer: B Explanation: b references the same list object as a; modifications through b affect a.
C) try: open('missing.txt') except FileNotFoundError: pass D) if os.path.exists('missing.txt'): open('missing.txt') Answer: C Explanation: Using a try/except block catches the FileNotFoundError and prevents the program from crashing.
Question 31. Which of the following statements about list slicing mylist[1:5:2] is true? A) It returns elements at indices 1, 2, 3, 4. B) It returns every second element from index 1 up to (but not including) index 5. C) It returns elements at indices 1, 3, 5. D) It returns the whole list reversed. Answer: B Explanation: The slice syntax is [start:stop:step]; here it picks indices 1 and 3 (step 2) up to index 5 (exclusive).
Question 32. What is the output of the following code?
def f(x, y=[]): y.append(x) return y print(f(1)) print(f(2))A) [1] then [2]
B) [1] then [1, 2] C) [1] then [1] D) [1, 2] then [1, 2] Answer: B Explanation: Default mutable arguments are evaluated once; the same list y is reused across calls, accumulating values.
Question 33. Which of the following statements correctly creates a generator that yields numbers 0-9? A) gen = (i for i in range(10)) B) gen = [i for i in range(10)] C) gen = {i for i in range(10)} D) gen = (i for i in range(10) if i % 2 == 0) Answer: A Explanation: Parentheses with a comprehension create a generator expression.
Question 34. In the context of the logging module, which level has the highest severity? A) DEBUG B) INFO C) WARNING D) CRITICAL Answer: D Explanation: Logging levels order from low to high: DEBUG, INFO, WARNING, ERROR, CRITICAL.
D) NameError Answer: C Explanation: nonlocal refers to the nearest enclosing scope (outer), allowing inner to modify x defined there.
Question 37. Which method of a list removes the first occurrence of a value and raises a ValueError if the value is not present? A) pop() B) remove() C) discard() D) delete() Answer: B Explanation: list.remove(value) deletes the first matching element and raises ValueError when absent.
Question 38. Which of the following statements about the enumerate() function is correct? A) It returns a list of tuples containing index and element. B) It returns an iterator yielding (index, element) pairs. C) It can only be used with dictionaries. D) It modifies the original iterable. Answer: B Explanation: enumerate produces an iterator that yields pairs of the form (index, item).
Question 39. Which of these is the correct way to create a virtual environment named venv using the built-in venv module? A) python -m venv venv B) virtualenv venv C) pip install venv && venv create D) python3 create venv Answer: A Explanation: The standard command is python -m venv.
Question 40. What does the @property decorator do? A) Converts a method into a class method. B) Allows a method to be accessed like an attribute, enabling getter behavior. C) Makes a method static. D) Prevents the method from being overridden. Answer: B Explanation: @property defines a getter; the method can be accessed without parentheses, appearing as an attribute.
Question 41. Which of the following is true about Python’s async and await keywords? A) They can be used in any function without restrictions. B) They enable asynchronous coroutines when used with an event loop. C) await can be used outside of an async function. D) async automatically runs the function in a new thread.
Question 44. Which of the following statements about Python’s set type is false? A) Sets are unordered collections. B) Sets can contain duplicate elements. C) Sets support membership testing in O(1) average time. D) Sets are mutable. Answer: B Explanation: Sets automatically discard duplicates; they store only unique elements.
Question 45. Which statement correctly creates a regular expression that matches a three-digit number? A) re.compile(r'\d{3}') B) re.compile(r'[0-9]{3,}') C) re.compile(r'\d+') D) re.compile(r'\w{3}') Answer: A Explanation: \d{3} matches exactly three digits; other options either allow more digits or match non-digits.
Question 46. Which of the following is the correct way to retrieve the Python version at runtime? A) sys.version_info
B) platform.python_version() C) os.version() D) Both A and B Answer: D Explanation: Both sys.version_info (tuple) and platform.python_version() (string) provide version information.
Question 47. What does the -m flag do when invoking the Python interpreter? A) Runs a module as a script. B) Enables memory profiling. C) Starts the interpreter in interactive mode. D) Compiles the script to bytecode only. Answer: A Explanation: python -m module_name searches sys.path for the module and executes its __main__ block.
Question 48. Which of these statements about the __repr__ method is accurate? A) It should return a string that, when passed to eval(), recreates the object. B) It is used by the print() function. C) It must return a byte object. D) It is called only for private attributes. Answer: A Explanation: __repr__ aims to produce an unambiguous representation, ideally one that could be used to reconstruct the object.