使用 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 值和标志(adjusted > 1)
Sort:按 adjusted 降序返回前 10 个
> Add a docstring to process_data()
"""过滤高于阈值的记录,若为 premium 则提升 10%,并按调整后数值返回前 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 参数的调用共享同一个默认列表对象, 导致多次调用间的元素不断累积。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 进行软件开发