使用 Claude Code 進行軟體開發
Dani Zysman
AI Curriculum Manager @ DataCamp

$ curl -fsSL https://claude.ai/install.sh | bash
更多資訊請參考:{https://code.claude.com/docs/en/overview}
$ cd /path/to/your/project
$ claude
常用指令:
/clear 清除對話紀錄/exit 或 Ctrl + C 結束工作階段/help 顯示可用指令def process_data(records, threshold=0.5):
result = []
for r in records:
if r.get('value') and r['value'] > threshold:
x = r['value'] * 1.1 if r.get('premium') else r['value']
result.append({'id': r['id'], 'adjusted': x, 'flag': x > 1})
return sorted(result, key=lambda d: d['adjusted'], reverse=True)[:10]
> What does process_data() do?
process_data(): 篩選、調整與排序
Filter:保留 value > threshold(預設:0.5)
Adjust:若 premium=True,提升 10%
Transform:輸出 id、adjusted 值,以及 flag(若 adjusted > 1)
Sort:依 adjusted 遞減取前 10 筆
> Add a docstring to process_data()
"""篩選超過門檻的紀錄,對 premium 加成 10%,並回傳 adjusted 值最高的前 10 筆。"""
def add_item(item, item_list=[]):
item_list.append(item)
return item_list
你看出問題了嗎?
> Find the bug in add_item() and fix it
已找到並修正:問題在可變動的預設參數。 使用 item_list=[] 代表所有未提供 list 參數的 add_item() 呼叫 會共用同一個預設 list 物件,導致項目在多次呼叫間累積。def add_item(item, item_list=None): if item_list is None: item_list = [] item_list.append(item) return item_list
| 問題 | 解法 |
|---|---|
| 「Context window exceeded」 | 使用 /clear 重設 |
| 觸發速率限制 | 稍候再試 |
| 結果不佳 | 將提示聚焦於單一任務 |

使用 Claude Code 進行軟體開發