Classes Flashcards

(8 cards)

1
Q

What is object-oriented programming ?

A

It is a software writing approach that helps you write classes that represent real-world things and situations, and create objects based on these classes.
When you write a class, you define the general behavior that a whole category of objects can have.

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

What is instantiation ?

A

Making an object from a class is called instantiation, and you work with
instances of a class.

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

What is a method ?

A

A function that’s part of a class is a method.

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

What is the init() method ?

A

The __init__() method at is a special method that Python runs automatically whenever we create a new instance based on the Dog class.

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

Whta is an attribute ?

A

Attributes are variables that are accessible through instances.
They are name with the prefix self.

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

What is a class ?

A

Think of a class as a set of instructions for how to make an instance. The class Dog is a set of instructions that tells Python how to make individual instances representing specific dogs.

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

How to set a default value for an attribute ?

A

Every attribute in a class needs an initial value, even if that value is 0 or an empty string. In some cases, such as when setting a default value, it makes sense to specify this initial value in the body of the __init__() method; if you do this for an attribute, you don’t have to include a parameter for that attribute.

Ex :

class Car():
def __init__(self, make, model, year):
“"”Initialize attributes to describe a car.”””
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0

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

What are the different ways to modify an attribute’s value ?

A

Directly
Through a method (update_ method )
By incrementing through a method.

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