parts of OOP

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

What does this code define?

class Dog:

A class (blueprint for objects).
Look for class keyword.

2
New cards

Identify the instance attribute:

def __init__(self):
    self.name = "Fido"

self.name (unique to each object).

Key: Any variable prefixed with self..

3
New cards

What’s the class attribute?

class Dog:
    species = "Canine"

species (shared by all Dog objects).

Key: Variables declared inside class but outside methods.

4
New cards

Which method is the constructor?

def __init__(self, age):
    self.age = age

__init__ (auto-called during instantiation).

Key: Always named __init__.

5
New cards

Is this a method or function?

def bark(self):
    print("Woof!")

Method (defined inside a class, takes self).

Key: Functions are standalone; methods belong to classes.

6
New cards

What does __str__ do?

Magic Method, defines how the object is printed (e.g., print(dog)).

Key: Look for __method__ names.

7
New cards

Find the local variable:

def calculate(self):
    total = self.price * 2

total (exists only inside the method).

Key: Variables not attached to self.

8
New cards

What’s special here?

@classmethod
def change_species(cls, new_species):
    cls.species = new_species

Class method (modifies class-level attributes via cls).

Key: Decorator @classmethod and cls parameter.

9
New cards

How do you create a Dog object?

my_dog = Dog() (calls __init__).

Key: ClassName() syntax.

10
New cards

Why does every method need self?

self refers to the current object instance.

Key: First parameter in instance methods.