Module 8: Classes Flashcards

1
Q

A class has ______ which are variables of the class and _______ which are functions to be called on instances of the class.

A

attributes
methods

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

The annotation of an attribute says _______ ________ ______

A

name
colon
type

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

Documentation for a class includes ________ and __________.

A

docstring
attribute annotations

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

______ methods start and end with two underscores, for the user to be able to use without defining them.

A

magic

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

__________ is used to give a more meaningful initialization of an object.

A

__init__

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

_________ and ________ are used to give a description of a printed object.

A

__repr__
__str__

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

_________ is used to redefine the comparison operator.

A

__eq__

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

a ________ is a function that is part of a class and will be called on an object.

A

method

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

All class methods must begin with _______ referential parameter which allows you to refer to the object that called this method.

A

self

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

Self is a value of _______ type as class being defined, so ______ the type annotation.

A

same
omit

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

While defining a class the class is not yet defined so _________ use the __________ inside the class definition. Instead, when referring to a value of the same class, use a ________ containing the name of the class.

A

cannot
name of the class
string

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

Instances of a class are _________.

A

objects

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

__init__ returns _________. ______ the annotation.

A

None
omit

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

Classes are ______ and can be _________ like dictionaries.

A

mutable
aliased

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

When using a class object, access the attributes and methods of the class by calling the __________ followed by _________ or __________.

A

object name
.attribute
.method(parameters)

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

Use ____________ to display whatever information of interest from a class. Typically used to display all attribute values of the class and tell the user which value is which.

A

__repr__

17
Q

To create a brand new object and copy all the attributes of another object use the format: _______________________

A

india_copy = Country(india.continent, india.leader, india.population)

18
Q

To alias an object use the format: ________________.

A

india_alias = india

19
Q

The default for how == is defined is _________. Often this is changed by overriding the __________ magic method. Now need to use ________ to determine if 2 objects are aliases of each other.

A

aliasing
__eq__
is

20
Q

With overriding __________ method the equality can be utilized for two values of _______ type. Use method ______________ to check whether the type of object_name is equal to class_name.

A

__eq__
any
isinstance(object_name, class_name)

21
Q

An object is ________ the same as its representation.

A

not