5. OOP Flashcards
1
Q
what casing is used for Class
A
Camel casing vs snake casing which is used for variable
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’)
3
Q
two major features of a Class
A
attribute and methods
4
Q
class object attributes
A
class Dog(): species = 'mammal'
5
Q
what is method
A
method is a function inside a class work in the object in some ways
6
Q
how to create a method
A
class Dog(): def bark(self,variable1, variable2): print(self.name)
7
Q
inheritence
A
class Dog(BaseClass): pass
8
Q
polymorphism
A
different class using the same method name
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