5. OOP Flashcards

1
Q

what casing is used for Class

A

Camel casing vs snake casing which is used for variable

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

how to create an instance and attribute

A

“init” method
self keyword can be something else, but just stick with self. it means it is associated with the specific instance

class Dog():
    def \_\_init\_\_(self,breed):
        self.breed = bread

my_dog = Dog(breed=’Husky’)

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

two major features of a Class

A

attribute and methods

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

class object attributes

A
class Dog():
    species = 'mammal'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is method

A

method is a function inside a class work in the object in some ways

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

how to create a method

A
class Dog():
     def bark(self,variable1, variable2):
         print(self.name)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

inheritence

A
class Dog(BaseClass):
    pass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

polymorphism

A

different class using the same method name

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

magic/Dunder methods

or how to print an instance

A

create special methods so that the class can be defined for build-in functions

e.g. string representation
 def \_\_str\_\_(self):
         return f'My name is {self.name}'
e.g. len representation
 def \_\_len\_\_(self):
         return self.radius
How well did you know this?
1
Not at all
2
3
4
5
Perfectly