What does OOP stand for?
Object Oriented Programming
What is the principle that is demonstrated by only the object itself having access to its attributes and methods?
Encapsulation
True
When opening a file in Python , when is the full file path needed?
When the file is not in the same directory as the python file.
What does the code
if __name__ == "__main__": do?
Only runs the code inside the if block if the file itself is the one being run (not another file that imports code in original file).
What is an instance of a class called?
What is class composition?
Using an instance of a class as an attribute of another class.
What is the visual tool we have been using that represents the details of the class - name, attrs, and methods.
UML diagrams
What are the 4 modes available when opening files?
r - read
w - write
x - create
a - append
True or False: When testing a class, you must test the methods but the constructor does not need to be tested.
False: The constructor and all the methods must be tested.
What is the difference between attributes and methods?
Attributes are properties and methods are functions that can be called. Attributes can be accessed but not called.
True or False: When a class inherits another class, it also inherits its attributes but not its methods.
False. It inherits all the attributes and methods.
In a class, where should input validation be done?
What is the difference between read/write and readlines/writelines?
read/write work with strings
readlines/writelines work with lists
What is the keyword for bringing in code from another python file?
import
What are __str__ and __repr__ and what are they used for?
__repr__ is used to recreate the object in its current state, the output is the exact syntax used to create the object, used for debugging
Method overriding is the implementation of which OOP principle?
Polymorphism
Why aren't abstract methods implemented in the abstract base class?
They are too abstract to have an implementation, an implementation would not make sense because the base class is too vague.
For example: The shape class is too vague to have an area method implementation.
What is the main benefit of using a context manager?
When should assertRaises be used?
When you want to test that an error is raised when a piece of code is executed.
An underscore before an attribute or method declaration means the attribute or method should be considered what?
ex: self._course = "Python", def _what_course(self):
private
True or False: An abstract base class cannot be instantiated.
True or False: Every abstract method must but be implemented in the abstract base class's derived class.
True.
True.
What is the difference between abstract methods and method overriding?
An abstract method never has an initial implementation, and is only implemented in the derived class.
Polymorphism and method overriding always has an original implementation in the base class.
True or False: Opening a file in w+ will not wipe the existing file and put the cursor at the beginning of the file.
False. It will wipe all the existing contents.
What is the difference between a python module and package?