Prompt Writing with GitHub Copilot
You’re just starting your coding journey. You know a few basics — maybe you’ve printed “Hello, World!” before — but you’re not comfortable writing full functions or solving problems on your own yet.
Your friend tells you about GitHub Copilot, an AI coding helper that suggests code as you type. You get excited and open VS Code, ready to try it.
You type:
1
# do something
Copilot suggests something weird — maybe random code you didn’t expect. Why? Because your prompt didn’t clearly say what you wanted.
What Is a Prompt?
A prompt in GitHub Copilot is any piece of text — typically a comment or partial code snippet — that gives the AI context and direction for what you want to accomplish.
When you write a prompt, you’re essentially telling Copilot:
"Here’s what I want you to do. Please complete it for me."
A prompt can be as simple as a one-line comment describing a function’s behavior or as detailed as a step-by-step outline of logic.
Why Prompt Quality Matters
Copilot uses your prompt to generate suggestions. If your prompt is vague or incomplete, you might get unexpected, incorrect, or overly generic code.
A good prompt can help you:
- Get more accurate, usable code faster
- Reduce the time you spend editing or rewriting
- Learn better coding habits by thinking clearly before implementation
Types of Prompts You Can Use
When using GitHub Copilot, you "talk" to it by writing prompts. Think of a prompt like giving instructions to a friend. There are different ways to prompt Copilot so it understands exactly what code you want. Let’s look at them one by one.
1. Descriptive Comments
This is the most common type of prompt for beginners. You simply write a clear comment in plain English describing what you want your code to do.
1
# Write a function that adds two numbers and returns the result
After typing this comment, you can start your function like this:
1
def
When you press Enter, Copilot will suggest:
1 2
def add_numbers(a, b): return a + b
Why it works
- You clearly tell Copilot what you want: a function that adds two numbers.
- No fancy words or extra details.
- It helps you learn how to structure functions step by step.
2. Partial Code Prompts
Instead of writing a full comment, you can start a line of code (for example, the name of a function). Copilot will try to guess what you want to finish.
1
def is_even(n):
When you press Enter, Copilot might suggest:
1
return n % 2 == 0
Why it works
- By giving the function name (
is_even
), Copilot understands your goal is to check if a number is even. - The parameter
n
hints that you’re working with one number.
3. Inline Comments
These comments are written inside existing code, usually inside a loop or function. They tell Copilot what to do next at that exact spot.
1 2 3 4
numbers = [1, -3, 5, -2, 8] for num in numbers: # skip negative numbers
When you type this comment and press Enter, Copilot might suggest:
1 2
if num < 0: continue
Why it works
- You give instructions for one small part of your code.
- Copilot suggests logic that matches the comment exactly.
Best Practices for Writing Prompts
Good prompts lead to better code suggestions. Let’s see how you can make your prompts clear and useful.
Be Specific
The more details you give, the better Copilot can help.
Weak Prompt
1
# Write a function
This is too general — Copilot doesn’t know what kind of function you want.
Strong Prompt
1
# Write a function that takes a list of numbers and returns a list with each number squared
With this, Copilot knows exactly what you want and gives you an accurate function.
Use Clear Language
Write your prompt like you’re talking to a friend who knows nothing about your idea. Avoid short forms or unclear words.
Unclear
1
# Do stuff with data
Clear
1
# Take a list of numbers and return a new list with only the even numbers
Break Down Large Tasks
If a task feels big, divide it into smaller steps. This makes it easier for both you and Copilot.
Example (Too Big)
1
# Read a file, clean it, analyze numbers, and create a chart
Better Approach
# Read a file and return a list of numbers
# Remove negative numbers from the list
# Calculate the average of the numbers
# Print a simple summary of results
Review and Edit
Even if Copilot writes code for you, you must always check:
- Does it do what I wanted?
- Can I understand each line?
- Are there mistakes?
Iterate (Try, Improve, Repeat)
Sometimes your first prompt won’t give the perfect code. You can make it better by adding more details or changing words.
Example Iteration
1. First try:
1
# Write a function to sort a list
2. Next, you decide to be more specific:
1
# Write a function to sort a list of numbers in descending order
3. Finally, you make it even clearer:
1
# Write a function to sort a list of numbers in descending order and return the sorted list
Each time, you help Copilot understand exactly what you want.
Common Prompting Mistakes to Avoid
1. Being Too Vague
1
# Handle data
2. Asking for Too Much at Once
1
# Build an app that takes user input, stores it, checks for errors, and displays graphs
3. Always remember: Copilot is a helper, not a teacher. You need to understand and test each line it suggests.
Key Takeaways
1. Write clear, simple, and specific prompts.
2. Break big tasks into small steps.
3. Always read and understand Copilot’s suggestions.
4. Don’t hesitate to improve your prompt if the first try isn’t perfect.
What’s Next?
Now that you know how to guide Copilot, we’ll move on to learning variables, data types, and operators — still using small, friendly prompts to help you practice and understand each concept step by step.