> For the complete documentation index, see [llms.txt](https://tomlin.gitbook.io/bei-shang-zi-guan-python-ke-cheng-2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tomlin.gitbook.io/bei-shang-zi-guan-python-ke-cheng-2/yi-.-ke-cheng-nei-rong/san-mo-shu-fang-fa/11.-__add__-self-obj.md).

# 11.  \_\_add\_\_(self, obj)

使用「**物件+obj**」時會執行此方法

### (1) 以下是「Score」類別：

```python
class Score:
    def __init__(self, name, *scores):
        '''
        建構元
        設定: 姓名, 不定個數的分數
        '''
        self.name = name
        self.scores = sorted(list(scores))

    def __add__(self, obj):
        return sum(self.scores)+obj
```

### (2) 主程式

```python
s = Score('王小明', 90, 80, 60, 40, 70, 30, 80)

print(s+0)
print(s+5)
```

### 執行結果

```
450
455
```
