




























































































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
This review guide supports candidates preparing for Python certification exams by covering core programming concepts, data structures, object-oriented programming, libraries, and practical coding scenarios. Includes extensive practice questions with explanations to reinforce coding logic and problem-solving skills.
Typology: Exams
1 / 118
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which term best describes Python’s execution model? A) Compilation to native machine code before execution B) Interpretation of source code line-by-line at runtime C) Translation to Java bytecode D) Execution only after conversion to C Answer: B Explanation: Python is an interpreted language; the interpreter reads and executes source code line by line, though implementations may use bytecode internally. Question 2. What is the purpose of the indentation in Python code? A) To separate statements with semicolons B) To define block scopes such as loops and functions C) To comment out code blocks D) To indicate variable types Answer: B Explanation: Indentation is mandatory in Python and determines the grouping of statements into blocks (e.g., the body of an if or def). Question 3. Which of the following is a valid Python identifier? A) 2data B) my-var C) _temp123 D) class
Answer: C Explanation: Identifiers may contain letters, digits, and underscores but cannot start with a digit and cannot be a reserved keyword like class. Question 4. What does the literal 0b1010 represent? A) Decimal 10 B) Octal 10 C) Hexadecimal 10 D) Binary 10 Answer: A Explanation: The prefix 0b indicates a binary literal; 0b1010 equals decimal 10. Question 5. Which operator has the highest precedence in Python? A) or B) and C) not D) ** Answer: D Explanation: Exponentiation (**) binds tighter than logical operators; it is evaluated before not, and, and or. Question 6. What is the result of 5 // 2 in Python? A) 2.5 B) 2
Question 9. What does the range(3, 8, 2) function produce? A) [3, 5, 7] B) [3, 4, 5, 6, 7, 8] C) [3, 5, 7, 9] D) [3, 6, 9] Answer: A Explanation: range(start, stop, step) generates numbers from start up to but not including stop, stepping by step. Here it yields 3, 5, 7. Question 10. Which list method adds an element to the end of the list? A) append() B) insert() C) extend() D) add() Answer: A Explanation: list.append(item) places item as the last element of the list. Question 11. What will len("Python") return? A) 5 B) 6 C) 7 D) 0 Answer: B
Explanation: The string "Python" contains six characters; len() returns that count. Question 12. Which of the following statements correctly reads a line of input from the user? A) data = input B) data = input() C) data = raw_input() D) data = scanf() Answer: B Explanation: input() is the built-in function that prompts the user and returns the entered string. Question 13. How can you change the separator between items printed by print()? A) print(a, b, sep="-") B) print(a, b, delimiter="-") C) print(a, b, join="-") D) print(a, b, split="-") Answer: A Explanation: The sep keyword argument defines the string inserted between multiple arguments. Question 14. Which statement imports the math module under the alias m? A) import math as m
Explanation: pip install downloads and installs the specified package from PyPI. Question 17. After executing import math; dir(math), what type of object is returned? A) List of attribute names B) Dictionary of functions C) Tuple of module metadata D) Set of numeric constants Answer: A Explanation: dir() returns a list containing the names of the module’s attributes, functions, and constants. Question 18. Which scope hierarchy is correct from innermost to outermost? A) Global → Enclosing → Local → Built-in B) Local → Enclosing → Global → Built-in C) Enclosing → Local → Global → Built-in D) Built-in → Global → Enclosing → Local Answer: B Explanation: Python resolves names by searching Local, then Enclosing (non-local), then Global, and finally Built-in. Question 19. What is the purpose of the raise statement? A) To create a new variable B) To trigger an exception manually
C) To end a loop D) To import a module Answer: B Explanation: raise explicitly raises an exception object, allowing custom error handling. Question 20. Which exception is raised when attempting to convert 'abc' to an integer with int('abc')? A) ValueError B) TypeError C) KeyError D) AttributeError Answer: A Explanation: The conversion fails because the string does not represent a valid integer, resulting in a ValueError. Question 21. What does the try … except … else … finally construct guarantee? A) The else block runs only if no exception occurs, and finally always runs. B) The else block runs after any exception, and finally runs only on success. C) Both else and finally run only when an exception is raised. D) Neither block is optional. Answer: A
C) join() D) replace() Answer: A Explanation: str.split() without arguments splits on any whitespace sequence. Question 25. What will 'Hello'.upper() return? A) 'HELLO' B) 'hello' C) 'Hello' D) 'HeLLo' Answer: A Explanation: The upper() method returns a new string with all characters converted to uppercase. Question 26. Which of the following correctly defines a class named Car with an initializer that stores make and model? A) class Car: def __init__(self, make, model): self.make = make; self.model = model B) class Car: def __init__(make, model): self.make = make; self.model = model C) class Car(self, make, model): pass D) def Car(make, model): pass Answer: A
Explanation: The initializer must accept self as the first parameter; option A follows proper syntax. Question 27. Which keyword is used to inherit from a base class Vehicle? A) inherits B) extends C) class Car(Vehicle): D) subclass Car from Vehicle Answer: C Explanation: In Python, a subclass is declared by placing the base class name in parentheses after the subclass name. Question 28. What does the super() function accomplish inside a subclass method? A) Calls the subclass’s own method recursively B) Accesses the parent class’s version of the method C) Creates a new instance of the subclass D) Deletes the parent class Answer: B Explanation: super() returns a proxy object that delegates method calls to the superclass, allowing reuse of its implementation. Question 29. Which of the following is an example of encapsulation? A) Defining a function inside another function B) Using a leading underscore to indicate a “private” attribute
Question 32. Which built-in function can retrieve the value of an attribute whose name is stored in a string variable attr_name? A) getattr(obj, attr_name) B) hasattr(obj, attr_name) C) setattr(obj, attr_name) D) delattr(obj, attr_name) Answer: A Explanation: getattr returns the attribute value; hasattr checks existence, setattr assigns, and delattr removes. Question 33. What will hasattr([1,2,3], 'append') return? A) True B) False C) None D) Raises an exception Answer: A Explanation: Lists have an append method, so hasattr returns True. Question 34. Which decorator turns a regular function into a property of a class? A) @staticmethod B) @classmethod C) @property D) @abstractmethod
Answer: C Explanation: @property allows a method to be accessed like an attribute, providing getter (and optionally setter) behavior. Question 35. What is the effect of applying @staticmethod to a method inside a class? A) The method receives the class as the first argument B) The method receives the instance as the first argument C) The method receives no implicit first argument D) The method becomes abstract Answer: C Explanation: A static method behaves like a regular function that lives in the class namespace; it receives no self or cls argument. Question 36. Which of the following best describes a metaclass in Python? A) A class that creates other classes B) A function that decorates methods C) An instance of a class that stores data D) A module that provides logging Answer: A Explanation: A metaclass is the “type” of a class; it defines how classes themselves are constructed. Question 37. What does type('MyClass', (object,), {}) return? A) An instance of MyClass
Explanation: shelve objects behave like dictionaries; item assignment stores data persistently. Question 40. Which design pattern ensures that a class has only one instance throughout a program? A) Factory B) Observer C) Singleton D) Strategy Answer: C Explanation: The Singleton pattern restricts instantiation to a single object. Question 41. In the Factory design pattern, what is the primary responsibility of the factory class? A) To store global configuration data B) To create objects without exposing the creation logic to the client C) To manage thread synchronization D) To log method calls Answer: B Explanation: A factory encapsulates object creation, allowing clients to request objects without knowing the concrete classes. Question 42. Which of the following best illustrates the Observer pattern in Python? A) A class that inherits from multiple base classes B) A function that decorates another function
C) A subject maintaining a list of callbacks that are invoked on state change D) A class that overrides __new__ Answer: C Explanation: Observers register with a subject; when the subject’s state changes, it notifies all registered observers. Question 43. Which Tkinter widget is used to display a single line of text that the user can edit? A) Label B) Button C) Entry D) Canvas Answer: C Explanation: Entry provides a one-line text field for user input. Question 44. In Tkinter, which method starts the event-loop that waits for user actions? A) mainloop() B) run() C) start() D) execute() Answer: A Explanation: root.mainloop() (or any widget’s mainloop) begins Tkinter’s event handling loop.
Question 47. Which method on a socket object is used to send data to a connected peer? A) recv() B) connect() C) send() D) listen() Answer: C Explanation: send() transmits bytes over a connected socket. Question 48. Which Python standard library module provides a lightweight relational database engine? A) sqlite3 B) mysqldb C) postgresql D) dbm Answer: A Explanation: sqlite3 ships with the standard library and implements the SQLite engine. Question 49. Which SQL command retrieves all rows from a table named employees? A) SELECT * FROM employees; B) GET ALL employees; C) FETCH employees; D) READ * employees;
Answer: A Explanation: SELECT * FROM is the correct syntax for retrieving all columns and rows. Question 50. In PEP 8, how many spaces are recommended for indentation? A) 2 B) 3 C) 4 D) 8 Answer: C Explanation: PEP 8 specifies four spaces per indentation level. Question 51. Which of the following is a correct way to write a docstring for a function? A) def f(): # This function does X B) def f(): """Perform X and return Y.""" C) def f(): // Perform X D) def f(): /* Perform X */ Answer: B Explanation: Triple-quoted strings placed as the first statement in a function become its docstring. Question 52. Which PEP contains “The Zen of Python”? A) PEP 8