What is object-oriented programming ?
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.
What is instantiation ?
Making an object from a class is called instantiation, and you work with
instances of a class.
What is a method ?
A function that’s part of a class is a method.
What is the init() method ?
The __init__() method at is a special method that Python runs automatically whenever we create a new instance based on the Dog class.
Whta is an attribute ?
Attributes are variables that are accessible through instances.
They are name with the prefix self.
What is a class ?
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 to set a default value for an attribute ?
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
What are the different ways to modify an attribute’s value ?
Directly
Through a method (update_ method )
By incrementing through a method.