1b. Class Basics Flashcards

1
Q

What keyword is used to define a class?

A

The “class” keyword is used to define a classing.

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

When are parentheses required in a class definition?

A

When the class being defined inherits from another.

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

What’s the naming convention for classes?

A

PascalCase

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

How do you instantiate a class in Python?

A

By calling the class with parantheses. (eg. classname=Book instantiation=Book())

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

What does the __init__ method do?

A

It initialises the new object with information.

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

Is the __init__ method the constructor of a class?

A

No. It’s more correct to call it the initialiser, because, internally, the object is already created before calling this method.

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

When is the __init__ method called for a class?

A

It is called when the class is instantiated. It runs before any other method can for any given class.

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

What’s the first argument any non-static class methods take?

A

It is the class instance. By convention, it is called “self”. However, it can really be called anything.

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

How do you access an object’s class attributes?

A

By using dot notation. (eg. book.title)

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