DEV Community

Jack Kisutsa
Jack Kisutsa

Posted on

# Python 101: Your Complete Beginner's Guide from Setup to Running Programs

Introduction

What I learned in my first week of Python, the mistakes I made, and the code that finally worked.

I have spent years working in Excel and Power BI, so I assumed Python would feel like a slightly harder version of a formula bar. It didn't. It felt like learning to drive after years of being a passenger: I knew where I wanted to go but I had never touched the controls.

This article is my honest record of the first four classes of my Python for Data Analytics course. It follows the order I learned things including the places I got stuck. If you are a complete beginner, I hope it saves you a few of the headaches I had.

All the code and screenshots are in my GitHub repository: [https://github.com/kisutsajack-ai/python-101-beginners-guide]. You can copy any example and run it yourself.

Day one: where do I even type this?

My first confusion was not about code. It was about tools. Python, VS Code, Jupyter and Google Colab all sounded like the same thing to me.

They are not. Python is the engine that runs your code. VS Code, Jupyter and Colab are just places where you write code for that engine. Installing VS Code alone gives you a nice editor and no Python at all. I wish someone had told me that before I spent twenty minutes wondering why nothing ran.

Our instructor started us on Google Colab, which needs only a Google account and a browser. No installation, no setup. I opened a new notebook, clicked Untitled0.ipynb at the top left and renamed it to day1_basics.ipynb then typed the below line and pressed Shift + Enter:

print("Hello from Colab")
Enter fullscreen mode Exit fullscreen mode

The output appeared right under the cell. It was a small thing but seeing it work on the first try made me feel like I could do this.

One thing I learned the hard way: files you upload to Colab disappear when the runtime resets. Keep anything important in Google Drive.

Installing Python on my laptop

Colab is great for practice but real projects run on your own machine, so the next step was installing Python locally.

On Windows, I used the installer from python.org. There is one tick box on the first screen that says "Add python.exe to PATH". I nearly skipped it. Our handout warned that this is the step most beginners miss and I can see why: if you miss it, the terminal tells you 'python' is not recognized and you feel like you broke something. Tick the box.

After installing, close any old terminal, open a new one, and check:

python --version      # Windows
python3 --version     # macOS / Linux
Enter fullscreen mode Exit fullscreen mode

If you see a version number, you are in. Mac and Linux users should type python3 and pip3, not python and pip.

Setting up VS Code

Next I installed VS Code and added two extensions from Microsoft: Python and Jupyter. Only install extensions from publishers you trust. In this case I downloaded the microsoft versions.

Then I made a folder for the course, opened it with File → Open Folder, and created a file called hello.py. The .py ending is how VS Code knows it is Python.

name = "Data Analyst"
print(f"Hello, {name}! Python is working.")
Enter fullscreen mode Exit fullscreen mode

I clicked the Run Python File button and the output showed up in the terminal at the bottom. If VS Code cannot find Python, press Ctrl + Shift + P, choose Python: Select Interpreter, and pick the version you installed.

Virtual environments

This was a new idea for me. A virtual environment is a private box of libraries for one project, so projects don't break each other. It sounds advanced, but it takes two commands:

# Windows (PowerShell)
python -m venv .venv
.venv\Scripts\Activate.ps1

# macOS / Linux
python3 -m venv .venv
source .venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

When it works, (.venv) appears at the start of your terminal line. On my machine PowerShell first refused with "running scripts is disabled on this system". The fix is to run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once and activate again.

Then I installed the libraries we will use later:

python -m pip install pandas numpy matplotlib seaborn notebook
Enter fullscreen mode Exit fullscreen mode

Notebooks and a warning

A notebook (.ipynb) splits your work into cells that run one at a time. That suits data work, because you see each step's result immediately. I used notebooks inside VS Code by creating analysis.ipynb and selecting my .venv as the kernel. VS code allows you to use both .py and .ipynb files.

The warning: cells can be run in any order and Python remembers every variable from every cell you ran. If your results look strange, restart the kernel and run everything from the top.

Variables: the = sign lies to you

In Excel, = starts a formula. In maths, it means "equals". In Python, it means assign. age = 40 reads as "store 40 in age".

customer_name = "Biko"
age = 40
monthly_spend = 3500.50
is_active = True

stock = 140
stock = stock - 50   # the latest assignment wins
print(stock)         # 90
Enter fullscreen mode Exit fullscreen mode

Python has naming rules it enforces: letters, digits and underscores only, never start with a digit, no spaces, and no keywords like if or class. Names are also case-sensitive, so Sales and sales are different variables.

Then there is PEP 8, the style guide. Breaking it won't crash your code but following it makes your work readable. Use snake_case for variables, UPPER_SNAKE_CASE for constants and descriptive names. total_revenue tells a reader something while x does not.

My favourite trick from this section was swapping two values in one line, with no third variable:

a, b = 14, 5
a, b = b, a
print(a, b)  # 5 14
Enter fullscreen mode Exit fullscreen mode

Data types: the bug that surprised me

Every value has a type: int, float, str, bool or None for missing values. The type decides what you can do with the value.

This is where I made my first real mistake. I had a price stored as text, "300" and multiplied it by 3, expecting 900. I got this instead:

price_text = "300"
quantity = 3
print(price_text * quantity)       # 300300300
print(int(price_text) * quantity)  # 900
Enter fullscreen mode Exit fullscreen mode

Python had not calculated anything. It repeated the text three times. No error, just a wrong answer. After that I understood why people say numbers stored as text are one of the most common problems in real datasets.

Converting between types is called casting, using int(), float(), str() and bool(). A few traps I now check for:

  • int("12.5") fails. Convert with float() first.
  • int(9.99) gives 9. It cuts the decimal and does not round.
  • int("1,500") fails because of the comma.

Input and output

print() shows results and input() collects them. The thing to remember is that input() always returns a string, even if the user types a number. Convert before doing maths:

units = int(input("Units sold: "))
price = float(input("Price per unit (KES): "))
total = units * price
print(f"Total sales: KES {total:,.2f}")
Enter fullscreen mode Exit fullscreen mode

The f before the quotes makes an f-string. Variables go inside { }, and the part after the colon controls the format. :,.2f gives thousands separators and two decimals, which is exactly what I would otherwise do with number formatting in Excel.

Strings: where data cleaning starts

This was the section that made Python feel useful. Real data is messy, and most cleaning is string work.

Python counts positions from 0, and negative numbers count from the end. Slicing uses text[start:stop], which includes start and stops just before stop:

order_id = "KE-2026-00451"
print(order_id[0:2])   # KE
print(order_id[3:7])   # 2026
print(order_id[-5:])   # 00451
Enter fullscreen mode Exit fullscreen mode

The methods I now use most are .strip(), .lower(), .title(), .replace(), .split() and .join().

My second real mistake was here. I wrote name.strip() on its own line and was confused when name still had spaces. String methods never change the original. They return a new string, and you have to save it:

name = " kimani "
name = name.strip()   # save the result back
Enter fullscreen mode Exit fullscreen mode

Once I understood that, chaining methods became satisfying. This one line turns "KES 17,500.00" into a number I can calculate with:

raw_amount = "KES 17,500.00"
amount = float(raw_amount.replace("KES", "").replace(",", "").strip())
print(amount)  # 17500.0
Enter fullscreen mode Exit fullscreen mode

Operators and a BODMAS lesson

The arithmetic operators are + - * / // % **. / always returns a float, // returns the whole part of a division, and % returns the remainder. The last two work well together for converting units:

minutes = 135
print(minutes // 60, "hrs", minutes % 60, "mins")  # 2 hrs 15 mins
Enter fullscreen mode Exit fullscreen mode

Python follows BODMAS, the order of operations from primary school. Forgetting brackets gave me a wrong average that looked believable:

a, b, c = 70, 80, 90
wrong = a + b + c / 3     # 180.0
right = (a + b + c) / 3   # 80.0
Enter fullscreen mode Exit fullscreen mode

The rule I took from this: when in doubt, add brackets. They cost nothing.

We also covered comparison operators (==, !=, >, <, >=, <=), logical operators (and, or, not) and membership operators (in, not in). I kept mixing up = and ==. One assigns, the other compares.

Conditionals: teaching code to decide

Conditionals let code choose a path. Three rules: the condition line ends with a colon, the code inside is indented four spaces, and Python runs only the first condition that is true.

score = 74

if score >= 80:
    grade = "A"
elif score >= 70:
    grade = "B"
elif score >= 60:
    grade = "C"
else:
    grade = "D"

print(f"Score {score} -> Grade {grade}")  # Grade B
Enter fullscreen mode Exit fullscreen mode

Order matters. If I had checked score >= 50 first, a score of 74 would have received the wrong grade. As an analyst, I immediately saw how this applies to segmenting customers or flagging records.

Putting it all together

The best part of the week was a mini project that used everything. It takes messy order data, cleans it, applies a tiered discount, validates a phone number and prints a receipt.

raw_name = "  jANE kimani  "
raw_phone = " 0712 345 678 "
raw_price = "KES 1,350"
raw_qty = "4"

name = " ".join(raw_name.split()).title()
phone = raw_phone.replace(" ", "")
price = float(raw_price.replace("KES", "").replace(",", "").strip())
qty = int(raw_qty)

subtotal = price * qty

if subtotal >= 5000:
    discount_rate = 0.10
elif subtotal >= 2000:
    discount_rate = 0.05
else:
    discount_rate = 0.0

discount = subtotal * discount_rate
total = subtotal - discount

valid_phone = (
    len(phone) == 10
    and phone.isdigit()
    and (phone.startswith("07") or phone.startswith("01"))
)

print("=" * 34)
print(f"{'ORDER SUMMARY':^34}")
print("=" * 34)
print(f"Customer : {name}")
print(f"Phone    : {phone} ({'valid' if valid_phone else 'check number'})")
print(f"Quantity : {qty} x KES {price:,.2f}")
print(f"Subtotal : KES {subtotal:>12,.2f}")
print(f"Discount : KES {discount:>12,.2f} ({discount_rate:.0%})")
print(f"TOTAL    : KES {total:>12,.2f}")
print("=" * 34)
Enter fullscreen mode Exit fullscreen mode

When the receipt printed correctly, with Jane Kimani, a valid phone number and a 10% discount applied, it felt like the first time I had built something real in Python.

Learning to read errors

Early on, error messages scared me. Now I treat them as clues. Read the last line first, because it names the error type and the cause:

  • SyntaxError: a missing colon, quote or bracket.
  • NameError: a name that doesn't exist, often a typo or a cell I forgot to run.
  • TypeError: mixed types, like "Age: " + 25.
  • ValueError: right type, impossible value, like int("ten").
  • ZeroDivisionError: dividing by zero, so check the divisor first.

The dangerous mistakes are the ones that raise no error at all: text repeated instead of multiplied, a missing bracket in an average, an unsaved .strip(). For these, I now test every formula on one example I can check by hand.

What I would tell a beginner

  1. Type every example yourself. Copy-pasting teaches your clipboard, not you.
  2. Predict the output before you run the code. When you are wrong, that is where you learn.
  3. Don't fear errors. Read the last line.
  4. Start with Colab if installation feels overwhelming, and move to your own laptop when you are ready.

I came in thinking Python would replace what I already knew. After a week, it feels more like an extension of it: the same logic I use in Excel and Power BI, but with the ability to automate it and apply it to far more data. Next up are lists, dictionaries and loops, which let me apply today's logic to thousands of records instead of one.

If you want to try the examples, everything is here: [https://github.com/kisutsajack-ai/python-101-beginners-guide].

If you are learning too, I would love to hear which mistake caught you out first.

Top comments (0)