Logo
Section 1 / 3

设置和内联代码补全

设置 GitHub Copilot,探索内联代码补全功能,并通过示例使用首次 AI 辅助提交。

检查点

设置和内联代码补全

设置 GitHub Copilot,探索内联代码补全功能,并通过示例使用首次 AI 辅助提交。

...
1 / 4

启动 VS Code

...
1 / 4

点击 Copilot 图标或打开任意文件。

代码示例

1def calculate_area(radius):

1 return 3.14 * radius * radius
...
Copilot 建议代码

Python

1# TODO: 实现第 n 个斐波那契数 2def fibonacci(n): 3 pass

JavaScript

1// TODO: 实现第 n 个斐波那契数 2function fibonacci(n) { 3 // ... 4}

Java

1// TODO: 实现第 n 个斐波那契数 2int fibonacci(int n) { 3 // ... 4}

C++

1// TODO: 实现第 n 个斐波那契数 2int fibonacci(int n) { 3 // 你的实现代码 4}
1def fibonacci(n):

代码示例

1def fibonacci(n): 2 if n <= 0: 3 return [] 4 elif n == 1: 5 return [0] 6 elif n == 2: 7 return [0, 1] 8 9 fib_sequence = [0, 1] 10 for i in range(2, n): 11 next_value = fib_sequence[i - 1] + fib_sequence[i - 2] 12 fib_sequence.append(next_value) 13 14 return fib_sequence
1git add .
1 git commit -m "通过 Copilot 添加斐波那契数列实现"
1git push
1def merge_sorted(a: list[int], b: list[int]) -> list[int]:
1merge_sorted([1, 3, 5], [2, 3, 4]) 2# → [1, 2, 3, 4, 5] 3 4merge_sorted([], [-2, -1]) 5# → [-2, -1] 6 7merge_sorted([7, 7, 7], [7]) 8# → [7]
1def merge_sorted(a: list[int], b: list[int]) -> list[int]:

Quiz

单选题

GitHub Copilot 的一个主要目标是什么?

1 / 3

智能使用Copilot

Copilot 聊天基础