Be the first to know and get exclusive access to offers by signing up for our mailing list(s).

Subscribe

We ❤️ Open Source

A community education resource

4 min read

Teaching Python with AI: A guide for educators

How to use AI as a teaching partner that encourages critical thinking instead of code copying.

There’s a lot of pushback on artificial intelligence in education. Many educators worry that AI threatens learning and that students will simply copy generated code rather than understand it. Should we ban AI from the classroom? Or should we embrace it as a teaching tool?

The answer is neither. We should use AI as a “tutor on demand.”

When a friend who was learning Python asked me to review her code for a tool assessing artificial intelligence’s impact on small businesses, it made me reconsider how I teach Python. How could I use AI not as a replacement for learning, but as a partner in it?

Using AI as a Socratic tutor for Python

Rather than banning AI from the classroom, educators can leverage it as a Socratic assistant. Instead of asking AI to “fix this code,” encourage students to ask AI specific questions like “Why is this loop not working?” or “What does this variable store?

This approach fundamentally changes the learning dynamic. Students engage more deeply with the underlying logic. They learn to ask better questions, think critically about their problems, and understand the “why” behind solutions rather than just the “what.”

By framing AI as a tutor that asks questions in return, you shift the power dynamic. Students become active learners asking for explanations, not passive recipients of generated code.

Teaching critical evaluation and code quality

It’s crucial to help students understand that generative AI doesn’t guarantee correctness. AI can introduce subtle logical errors, performance issues, or inefficient approaches. Students need to learn how to evaluate the code AI generates.

Teach students to:

  • Test their code thoroughly
  • Ask “Does this actually solve the problem?
  • Compare different solutions and understand trade-offs
  • Recognize when AI suggestions might be suboptimal

This critical lens transforms AI from a shortcut into a learning tool that teaches discernment.

Read more: The 5 most common mistakes new Linux users make

Learning through multiple solutions

One of AI’s greatest strengths in education is showing students that multiple approaches exist to solve the same problem. A simple task like drawing a circle in Python can be done several ways.

I once asked an AI agent: “Draw a circle with Python.” I was thinking of the turtle module, but the AI generated code using matplotlib instead:

import matplotlib.pyplot as plt

# Create a figure and an axis
fig, ax = plt.subplots()

# Create a circle patch (Center: x=0, y=0, Radius=5)
circle = plt.Circle((0, 0), 5, color='blue', fill=False, linewidth=2)

# Add the circle to the axis
ax.add_patch(circle)

# Set equal scaling so the circle is not distorted into an oval
ax.set_aspect('equal', adjustable='datalim')

# Automatically scale the plot limits to show the circle
ax.autoscale_view()

# Display the plot
plt.title("Circle using Matplotlib")
plt.grid(True)
plt.show()
matplotlib blue circle graph python example
Screen capture by Don Watkins CC-BY-SA 4.0

I wouldn’t have thought of that approach on my own. This is powerful: Students can see that there are always multiple valid solutions, each with different trade-offs. This expands their thinking and shows them the breadth of Python’s ecosystem.

Read more: What to do when your AI starts going in circles

Open source tools for teaching Python

Making programming accessible and engaging matters. The combination of AI with open source tools ensures students learn effectively while enjoying the process.

VSCodium (an open source version of Visual Studio Code) is lightweight and works well with AI assistants. Thonny is specifically designed for beginners, with a built-in Python interpreter and visual debugging. Mu provides a simple, distraction-free environment perfect for learning.

These tools, combined with thoughtful use of AI, create an engaging learning environment where students can experiment freely without cost or complexity.

The future of Python education

Rather than viewing AI as a threat to learning, embrace its potential to enhance teaching. AI can make programming education more accessible, more engaging, and more effective when used thoughtfully.

The goal isn’t to replace human instruction. It’s to create a learning environment where students explore concepts deeply, ask better questions, and understand not just how to code, but why different solutions exist. Through collaborative exploration with AI as a tool, you cultivate programmers who are skilled, thoughtful, and ready to innovate.

More from We Love Open Source

This article is adapted from “Teaching Python” by Don Watkins, and is republished with permission from the author.

The opinions expressed on this website are those of each author, not of the author's employer or All Things Open/We Love Open Source.

Working on something worth sharing? Write for us.

Contribute to We ❤️ Open Source

Help educate our community by contributing a blog post, tutorial, or how-to.

Two World-class Events

If you didn't make it to All Things AI, check out the event summary, and make plans to join us October 19-20 for All Things Open.

Open Source Meetups

We host some of the most active open source meetups in the U.S. Get more info and RSVP to an upcoming event.