How to Use GitHub Copilot to Write Your First Python Script in 2 Hours
How to Use GitHub Copilot to Write Your First Python Script in 2026
If you're a beginner looking to dive into Python scripting, the prospect can feel daunting. You might wonder where to start or how to avoid the common pitfalls. What if I told you that you could leverage AI to help you write your first Python script in just two hours? Enter GitHub Copilot, an AI-powered coding assistant that can significantly speed up your development process.
In this guide, I'll walk you through the steps to use GitHub Copilot effectively, share my experiences, and offer practical advice on what you can realistically expect.
Prerequisites: What You Need Before Starting
Before you jump into coding, make sure you have the following:
- A GitHub account: You’ll need this to access Copilot.
- Visual Studio Code (VS Code): This is the code editor where you'll be writing your script. Download it from here.
- GitHub Copilot subscription: As of June 2026, Copilot costs $10/month after a free trial. You can sign up for it here.
- Basic understanding of Python: Familiarity with variables, loops, and functions will help, but Copilot can guide you through most of it.
Step 1: Setting Up GitHub Copilot in VS Code
- Install VS Code: If you haven't already, download and install Visual Studio Code.
- Install the GitHub Copilot extension: Open VS Code, go to Extensions (Ctrl+Shift+X), and search for "GitHub Copilot". Click to install.
- Sign in to GitHub: After installation, you'll need to sign in to your GitHub account to activate the extension.
Expected Output: You should see a Copilot icon in the VS Code sidebar, indicating that it’s ready to assist you.
Step 2: Starting Your First Python Script
- Create a new file: In VS Code, create a new file and save it with a
.pyextension (e.g.,my_first_script.py). - Write a comment to describe what you want to do: For example, type
# Create a simple calculatorat the top of your file. - Invoke Copilot: Start typing your function or logic, and Copilot will suggest completions. For instance, type
def add(a, b):and wait for Copilot to suggest the function body.
Expected Output: You should see a suggested function that adds two numbers.
Step 3: Completing Your Script
Continue writing your script by defining other functions like subtraction, multiplication, and division. Use comments to guide Copilot on what you want next. For example:
# Create a function for subtraction
def subtract(a, b):
Expected Output: Copilot should suggest a function that performs subtraction.
Troubleshooting: What Could Go Wrong
- Copilot doesn’t suggest anything: Make sure you’re connected to the internet and that you have an active Copilot subscription.
- Suggestions don’t make sense: Sometimes Copilot might miss the mark. Don’t hesitate to edit the code it suggests or write your own. It’s not perfect, but it’s a great starting point.
What's Next: Expanding Your Skills
Once you've completed your first script, here are some paths to consider:
- Explore Python libraries: Look into libraries like Pandas and NumPy for data manipulation.
- Build a small project: Try creating a simple web app using Flask or a command-line tool.
- Learn about Git and version control: This will help you manage your projects better.
Conclusion: Start Here
Using GitHub Copilot can significantly reduce the time it takes to write your first Python script. With a solid setup and some basic Python knowledge, you can have a functional script in just two hours. Remember, it's okay to edit Copilot's suggestions. The goal is to learn and grow as a coder.
If you're ready to get started, follow the steps outlined above and don't forget to experiment. Happy coding!
Follow Our Building Journey
Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.