OOP
OOP
OOP
File I/O
Etc
100

What does OOP stand for?

Object Oriented Programming

100

What is the principle that is demonstrated by only the object itself having access to its attributes and methods?

Encapsulation

100
True or False: The inputs in the constructor must equal the init arguments defined.

True

100

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.

100

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).

200

What is an instance of a class called?

A class object.
200

What is class composition?

Using an instance of a class as an attribute of another class.

200

What is the visual tool we have been using that represents the details of the class - name, attrs, and methods.

UML diagrams

200

What are the 4 modes available when opening files?

r - read

w - write

x - create

a - append

200

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.

300

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.

300

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.

300

In a class, where should input validation be done?

In the init function.
300

What is the difference between read/write and readlines/writelines?

read/write work with strings

readlines/writelines work with lists

300

What is the keyword for bringing in code from another python file?

import

400

What are __str__ and __repr__ and what are they used for?

__str__ is used to display a subset of information about the object, used mostly in development when verifying object creation or method validation


__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

400

Method overriding is the implementation of which OOP principle?

Polymorphism

400

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.

400

What is the main benefit of using a context manager?

The file is closed automatically when the context is exited.
400

When should assertRaises be used?

When you want to test that an error is raised when a piece of code is executed.

500

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

500

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.

500

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. 

500

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.

500

What is the difference between a python module and package?

A module is a single python file with statements inside, and a package is a collection of modules.
M
e
n
u