Quiz 5 Material Flashcards

1
Q

classes create ______ that encapsulate both data and methods

A

objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

variables + methods = ________

A

attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the return type of math.floor()?

A

a math object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is math.ceil() called?

A

a constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

can you import classes?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how would you write the heading for a class called MyClass? AKA class definition

A

class MyClass:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is an instance/object of a class?

A

it is one particular creation of the class (kind of like a recipe)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is the first method that is in the class and how is it written?

A
  • it is the constructor that is call when you create an object of the class
    def __init__(self, parameters)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

public vs private attributes

A

public attributes - which are open to access by anyone
private attributes - which are only available to the class object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

accessor methods

A

providing some public means of accessing private elements of our class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

write a private and public attribute for charge?

A

private: self.__charge
public: self.charge

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

the __str__ method

A

it is common practice to include a method that provides a representation of an object as a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

are the __init__ method and the __str__ method called by invoking their actual names?

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

if we don’t use self, then the variable only exists in the scope of the particular ________

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

does self have to be the first parameter?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

steps for writing to a file

A
  1. open a file for writing – outfile = open(filename, ‘w’) OR with open(filename,’w’) as outfile:
  2. write to the file – outfile.write() OR print(…, file=outfile)
  3. close the file – outfile.close()
17
Q

what is the difference between opening a file in ‘w’ mode and opening a file in ‘a’ mode

A

‘w’ mode - OS will erase everything that was already there
‘a’ mode - OS will append to existing file