Python with AI Tutorial · Chapter 1 of 48
This Python introduction explains what Python is, what people build with it and why it is the most useful first programming language for anyone who works with data, spreadsheets or reports. Python is a free, readable, general-purpose language, and in this course you will learn it side by side with an AI assistant that explains and fixes your code.
What is Python?
Python is a high-level programming language created by Guido van Rossum and first released in 1991. It is interpreted, which means you write a line of code and run it immediately without a compile step, and it is famous for syntax that reads almost like English.
print("Hello, Python!")
print(2 + 3)
Output: Hello, Python! 5
That is a complete Python program. No braces, no semicolons, no boilerplate class wrapping the code. You will see the same simplicity in every chapter of this course.
What is Python used for?
Python is a general-purpose language, but four areas dominate real-world use, and all four appear later in this course.
- Data analysis and reporting – the pandas library reads Excel and CSV files, cleans them and summarises millions of rows in seconds.
- Automation – rename 500 files, merge 40 monthly workbooks, send a report by email, all on a schedule.
- Artificial intelligence – almost every AI tool, from ChatGPT to image generators, is built or scripted in Python.
- Web and APIs – frameworks such as Django and Flask power sites, and the
requestslibrary pulls live data from any web service.
Here is a taste of the data side. With a plain list of monthly sales, Python can total, average and find the best month in three lines.
sales = [12500, 14200, 9800, 15600, 13100]
print("Total:", sum(sales))
print("Average:", sum(sales) / len(sales))
print("Best month:", max(sales))
Output: Total: 65200 Average: 13040.0 Best month: 15600
Python compared with Excel and VBA
If you already live in Excel, Python is not a replacement but an upgrade. Excel is brilliant for looking at data; Python is brilliant for processing it repeatedly, at scale, without copying formulas down a column.
| Task | Excel / VBA | Python |
|---|---|---|
| Rows it handles comfortably | About 1 million | Limited only by memory (tens of millions) |
| Repeating a report each month | Manual steps or a VBA macro | One script, one command |
| Combining many files | Power Query or copy-paste | A short loop with pandas |
| Learning curve | Formulas easy, VBA dated | Readable syntax, huge community |
| Works outside Office | No | Yes: web, servers, cloud, AI |
VBA is tied to Microsoft Office and has barely changed since the 1990s. Python skills transfer to any job, and since 2023 Python even runs inside Excel cells, which we cover in the Python in Excel chapter.
# The Excel formula =IF(A2>=10000, "Target met", "Below target") in Python
revenue = 12500
if revenue >= 10000:
print("Target met")
else:
print("Below target")
Output: Target met
Why Python is easy to read
Python uses indentation instead of brackets to show which lines belong together. Once you get used to it, the structure of a program is visible at a glance. Compare a loop that prints each employee with their department.
employees = {"Asha": "Finance", "Rahul": "Sales", "Meera": "HR"}
for name, dept in employees.items():
print(name, "works in", dept)
Output: Asha works in Finance Rahul works in Sales Meera works in HR
print works, Print raises NameError. Keep everything lowercase until a chapter tells you otherwise.Python versions: 2 vs 3
Python 2 reached end of life in 2020. Everything in this course uses Python 3, specifically 3.12 or newer. If you see old tutorials with print "hello" (no brackets), they are Python 2 and will not run today. You can check which version you have from the code itself.
import sys
print(sys.version_info.major, sys.version_info.minor)
Output: 3 12
How this course uses AI assistants
Learning to code in 2026 is different from learning it ten years ago. ChatGPT, Claude and GitHub Copilot can explain any line, spot a typo in seconds and suggest a better approach. They are not a shortcut around understanding; they are a tutor who never gets tired. Every chapter therefore has two layers:
- The W3Schools layer – a short explanation, a runnable example and its exact output. Type it yourself; do not paste.
- The AI layer – “Try it with AI” boxes with a ready-made prompt. Paste the prompt into your assistant, read the answer critically, then run the code it gives you.
The rule of thumb: write first, ask the AI second, and always run the result. The Python with AI assistants chapter later in the course goes deep on prompting, and the debugging with AI chapter shows how to hand an error message to a model and get a fix.
Ask your assistant to explain the sales example line by line, then extend it with a realistic business question.
Explain line by line what this Python code does, as if I have never programmed before. Then add one line that prints which month (1 to 5) had the highest sales:
sales = [12500, 14200, 9800, 15600, 13100]
print("Total:", sum(sales))
print("Average:", sum(sales) / len(sales))
print("Best month:", max(sales))
Use the assistant to map your current Excel work onto Python so the rest of the course feels relevant.
I am an Excel user who builds monthly sales and expense reports with VLOOKUP, pivot tables and a few VBA macros. I am starting to learn Python. List five specific tasks from that workflow that Python would do better than Excel, and for each one name the Python library I will eventually use. Keep it under 200 words.
Common mistakes
- Following Python 2 tutorials and getting a
SyntaxErroronprintwithout brackets. - Trying to learn every library at once. Learn the core language first (chapters 1 to 24), then pandas.
- Copying AI-generated code without running it. Always execute and read the output.
- Assuming Python replaces Excel. It complements it; you will still deliver results in a workbook.
- Skipping installation and using only online editors. Set up Python locally in the next chapter so you can work with real files.
Exercise
Without installing anything yet, predict the output of this program. Then check your answer.
invoices = [450, 1200, 880]
print(len(invoices))
print(sum(invoices))
print(max(invoices) - min(invoices))
Show answer
Output: 3 2530 750
len counts the items, sum adds them, and the last line subtracts the smallest invoice (450) from the largest (1200).
Related chapters
FAQ
Is Python hard to learn for a non-programmer?
No. Python was designed to be readable, and most Excel users write a working script within their first hour. The hardest part is installing it, which the next chapter walks through step by step.
Should I learn Python or VBA for Excel automation?
Learn Python. VBA only works inside Microsoft Office, while Python automates Excel through libraries such as openpyxl and pandas and also handles databases, web data and AI.
Can I learn Python using only ChatGPT or Claude?
An AI assistant is an excellent tutor, but you still need to type, run and break code yourself. This course pairs each concept with a prompt so the AI explains while you practise.
Working with spreadsheets too? Ready-made Excel, Google Sheets and Power BI templates are at NextGenTemplates.com.
Chapter 1 of 48 · Python with AI: all 48 chapters



