Hello, world!
BAA1118 - Introduction to Python Programming
Since 2019, I have been teaching Data Analytics and Statistics at DCU Business School.

Available on the module’s loop page and, more importantly, online at:
| Week | Topic |
|---|---|
| 2 | Variables, types and operators |
| 3 | Collections: lists, dictionaries and friends |
| 4 | Control flow: conditions and loops |
| 5 | Functions, modules and packages |
| 6 | From Colab to your own machine |
| 7 | Data manipulation with pandas |
| 8 | Aggregating, joining and reshaping |
| 9 | Data visualisation |
| 10 | Linear regression and prediction |
No previous experience is assumed. We start from zero.
Every lecture has “Your Turn” slides. Those are the lecture. The rest is context.
Modern data analytics uses free and open-source languages:
Python is also a general purpose language: the same skill writes a data analysis, a web scraper, an automation script, or a machine learning model.
Python is:

The value of code is reproducibility: the same script run on new data gives you the new answer in one second.
| Excel | Python | |
|---|---|---|
| Small, one-off table | Excellent | Overkill |
| 2 million rows | Impossible | Fine |
| Same report every month | Copy-paste | One command |
| Show what you did | Click history lost | The script is the record |
| Fix a mistake in step 2 | Redo everything | Change one line, rerun |
They are not competitors. Most analysts use both.
There are two key concepts to keep separate:
At its simplest, Python is like a car’s engine, while an IDE is like a car’s dashboard.

Does the work. You never look at it directly.

Where you type, where you see results, where errors are highlighted.
Anaconda is a fifth option: it bundles Python, an IDE and 1,500 packages in one 1 GB installer. Convenient, and it hides a lot.
From week 6 this module uses VS Code with Python installed from python.org, and we install each package ourselves. You will understand every piece of your own setup, and it is what you will meet in a job.
Installing software on 60 different laptops in a 2-hour lecture is a guaranteed way to teach nothing.
For weeks 1 to 5 we use Google Colab:
In week 6 you will install Python and VS Code on your own laptop, build a virtual environment for this module, and we will never look back.
In your web browser (Chrome, Firefox, Edge, Safari):
You now have a .ipynb file saved in your Google Drive, in a folder called Colab Notebooks.
Source: Fred Hutch Data Science Lab, Introduction to Python
A notebook is a document made of cells. There are two kinds:
Contain Python. Pressing Shift + Enter runs the cell and prints the result underneath.
Contain text written in Markdown. Used for titles, explanations, and comments to your future self.
A notebook is therefore a report and a program at the same time. That is why it is the standard tool in data analytics.
Source: Danilo Freire, DATASCI 151 course tutorials
When you run your first cell, Colab connects to a runtime: a small virtual computer that holds your Python session.
Runtime -> Restart session gives you a clean slateThis is not a bug. Restarting and rerunning from the top is how you check that your notebook actually works.
BAA1118_week1 (click the title, top left)# My first notebookprint() displays something on the screen.
A code cell also shows the value of its last line without print().
A result you do not store disappears.
price, vat and total are variables. The = sign does not mean equality: it means “take what is on the right, and give it this name”.
We will spend all of next week on this.
This is the number one cause of “but it worked five minutes ago”.
The small number in [ ] to the left of each cell tells you the order in which cells were actually run.
A shop sells 340 units of a product at €12.99 each. The cost per unit is €7.50.
In a new code cell:
print()The profit is 1866.6000000000004 euros
Yours does not have to look like this. It has to give the same number.
The one skill that separates people who learn to code from people who give up is reading the error message.
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[9], line 1 ----> 1 print("The total is: " + 42) TypeError: can only concatenate str (not "int") to str
Read it bottom up:
TypeError here means: you cannot add text and a numberSyntaxError: a bracket or quote is not closed. Look at the line before the one mentioned.
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[11], line 1 ----> 1 print(revenu) NameError: name 'revenu' is not defined
NameError: the name does not exist. Almost always a typo, or a cell you did not run.
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[12], line 1 ----> 1 print("5" * "3") TypeError: can't multiply sequence by non-int of type 'str'
TypeError: the operation makes no sense for these kinds of value.
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[13], line 1 ----> 1 Print("hello") NameError: name 'Print' is not defined
NameError again, and the reason is important: Python is case sensitive. Print, print and PRINT are three different names.
Steps 1 to 3 solve about 80% of errors in this module, and they take 20 seconds.
Run each line in its own cell. For each one, write in a text cell which error type it produces and what the fix is.
Then fix all five so that each prints something sensible.
| Line | Error | Why |
|---|---|---|
"Total: " + 100 |
TypeError |
text plus number |
3 + "3" |
TypeError |
same, other way round |
prnt("hello") |
NameError |
typo in the function name |
print("hello world) |
SyntaxError |
closing quote missing |
print(Price * 2) |
NameError |
Price was never assigned |
Two error types cover almost everything you will meet in week 1: you used a name that does not exist, or you combined types that do not go together.
You all have access to ChatGPT, Claude, Copilot and Gemini. Colab has Gemini built in.
Pretending otherwise would be silly. Using them well is now part of the skill.
Important
Using an AI assistant is allowed in this module, including in the assessment, provided you can explain every line you submit. I will ask.
The assistant writes a plausible answer. Only you can check it is the right one.
Weak prompt:
make a chart of my data
Strong prompt:
I have a pandas DataFrame called
saleswith columnsregion(text),month(text) andrevenue(float). Write Python using seaborn to plot mean revenue per region as a bar chart, with axis labels in euros. Explain each line.
The difference is context, names, types, and the request to explain.
You are not being trained to produce code. You are being trained to judge code.
Copy this into a cell. It contains three errors.
Total: 54.0
Three errors, three different lessons: case sensitivity, consistency, and text vs numbers.
Colab autosaves to Google Drive, but you should know the three exports:
File -> Save a copy in Drive: your working copyFile -> Download -> .ipynb: the notebook file, what you submitFile -> Download -> .py: the code only, no outputWarning
Runtime -> Run all before submitting anything. A notebook that only works in the order you happened to click is a notebook that does not work.

For this module, none of these are required. The lecture and the exercises are enough.
Content and ideas of this lecture borrow from:

Thanks for your attention and don’t hesitate to ask if you have any questions!
Comments
Anything after a
#is ignored by Python.Comments are written for the person reading the code in six months, who is almost always you.
Tip
Write comments explaining why, not what.
# add 1 to xis useless.# months are 0-indexed in this fileis gold.