Let's go through each question.
Question 1: Which of the following is false?
- A stack uses a last in, first out (LIFO) approach (True)
- A heap must be manually managed. (True)
- A stack automatically deallocates space when variables are no longer needed. (True)
- A heap is generally faster than a stack. (False)
Answer: A heap is generally faster than a stack. (This statement is false; generally, the stack is faster than the heap due to how they manage memory.)
Question 2: True or False? In Python, a file is always automatically closed for you after you are done reading it or writing to it.
The answer is False. In Python, files are not automatically closed; you need to close them explicitly or use a with
statement to ensure they are closed automatically at the end of the block.
Answer: False
Question 3: What type of file is best for storing discrete items that are stored in rows? The most suitable option for storing discrete items in rows is a CSV (Comma-Separated Values) file, as it is designed for tabular data where each row is a separate entry.
Answer: CSV
Question 4: Which of the following is the correct way to instantiate an object belonging to the user-defined class Dog that has attributes of name and breed?
The correct way to instantiate an object in Python is to directly call the class name followed by the arguments needed in parentheses. The option pet = Dog("Spot", "Dalmatian")
follows this syntax correctly.
Answer: pet = Dog("Spot", "Dalmatian")
Summary of Answers:
- A heap is generally faster than a stack. (False)
- False
- CSV
- pet = Dog("Spot", "Dalmatian")