---
# System prepended metadata

title: DAY 10 - 類別 Class

---

# DAY 10 - 類別 Class

### 程式習慣 - 主程式
python沒有主/副程式的概念，但寫大型程式時為了避免最外層程式雜亂，會建議用主程式的概念去寫
```python=
def AAA():
    for i in range(5):
        print("Hello World")

def __main__():
    AAA()

if __name__ == "__main__" :
    __main__()
```


### Class

```python=
class Dog():

    def __init__(self, name, weight):
        self.name = name #self就是dog01 || dog01.name = tony
        self.weight  = weight

    def eat(self):
        print(self.name + " is eating")
    
    def sleep(self):
        print(self.name + " is sleeping")

    def update_weight(self, weight):
        self.weight = weight
    
    def add_weight(self, add):
        self.weight += add

class Shiba(Dog):
    def __init__(self, name, weight, color):
        super().__init__(name, weight)
        self.color = color

class Poodle(Dog):
    def __init__(self, name, weight, size):
        super().__init__(name, weight)
        if size == 1:
            self.size = "teacup"
        elif size == 2:
            self.size = "toy"
        elif size == 3:
            self.size = "miniature"
        elif size == 4:
            self.size = "standard"

dog01 = Shiba("alex",12,"black")

dog02 = Poodle("amy",6,2)

print(dog02.size)

```