Smart Inline Completions: Use Cases, Examples, and Exercises
Code Completion
Code completion is probably the most used feature of GitHub Copilot, and also the most obvious one. It's used naturally as you write code, without any special action except typing and using the TAB key to accept the suggestion.
It helps you write code faster by suggesting code completions as you type. To use code completion, start typing a line of code, and GitHub Copilot will suggest completions based on your code's context. You can then select a completion from the list of suggestions, and Copilot will insert the code for you.
Open VS Code and start by creating a file named main.py. Type the following code:
for i in range(10):
for j in range(10):
As you type the code, GitHub Copilot will suggest completions for the nested loop. You can select a completion from the list of suggestions, and Copilot will insert the code for you.
Code completion example
Copilot may suggest multiple completions based on the context of your code. For example, it may suggest
print(i, j)
and
print(i * j)
To choose the desired completion, use the arrow keys to navigate through the list of suggestions. Once you've selected the one you want, use the TAB key to accept the suggestion and insert the code into your file. If you want to accept the suggestion word by word - which can be useful when you want to modify the suggestion slightly - use the CTRL + right arrow keys.
Try It Yourself: Create a Python program that capitalizes the first letter of a string. For example, the function should return "Hello" when called with "hello" as an argument. Solve the problem using five different methods.
Start by writing the function in a file named main.py, where you will add the initial function signature. You can use the following one for the first method:
def capitalize_first_letter_1st_method(string):
Wait for the suggestion from code completion, then repeat the same process for the other methods.
def capitalize_first_letter_2nd_method(string):
.... <-- [Let Copilot generate the code here]
def capitalize_first_letter_3rd_method(string):
.... <--Building with GitHub Copilot
From Autocomplete to Autonomous AgentsEnroll now to unlock all content and receive all future updates for free.

