Ep 1: Learning Python: My Beginner’s Brain Dump & Tips

Join me as I start learning Python, make mistakes, and share tips, cheat sheets, and resources for fellow beginners.

5/8/20243 min read

Day 1 of me vs. Python: I have no idea what I’m doing.

I signed up for DataCamp’s Introduction to Python (4 hours of chaos). Some moments: “Ahhhh, I get it!” Other moments: “WHAT EVEN HAPPENED??” honestly my brain was doing somersaults.

I get bored doing the same thing over and over, so the idea of automating stuff finally dragged me into actually trying. If I survive this, maybe I’ll build something cool later. Or just crash my laptop in spectacular fashion. Either way it’s going to be a ride.

I’ve been keeping a tiny cheat sheet for myself, because let’s be real Google only gets you so far. If it helps you too, you’re welcome:

Here’s some stuff I’ve actually learned

1. Variables & Data Types

Variables = labels for stuff. Numbers, text, True/False nonsense.

height = 1.79 # float
weight = 68.7
# float
bmi = weight / (height ** 2)
age = 25
# int
name =
"Alice" # str
is_student =
True # bool
print(
"Height:", height)
print(
"BMI:", bmi)
print(
"Type of weight:", type(weight))

Output

Height: 1.79
BMI: 21.44127836209856
Type of weight: <
class 'float'>

2. Operators & Assignment

Operators = math + string magic.

print(5 + 3) # add numbers
print(10 / 4)
# division
print(2 ** 3)
# exponent
print(
"Hello" + "World") # string concatenation

savings = 100
monthly = 10
new_savings = monthly * 4
total = savings + new_savings
print(
"Total savings:", total)

Output

8
2.5
8
HelloWorld
Total savings: 140

3. Lists & List Manipulation

Lists = fancy containers for your chaos. Slice, dice, add, delete… boss your data around.

heights = [1.79, 1.65, 1.80]
fam = [[
"Liz", 1.65], ["Emma", 1.70]]
areas = [
"hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.5]
# Access elements
print(fam[0])
print(fam[-1])
print(areas[1])
print(areas[-1])
# Slicing
downstairs = areas[:6]
upstairs = areas[-4:]
print(
"Downstairs:", downstairs)
print(
"Upstairs:", upstairs)
# Modify elements
areas[-1] = 10.50
areas[4] =
"chill zone"
# Add & remove elements
areas = areas + [
"poolhouse", 24.5]
areas.append(
"garage")
del areas[-2]
# Copy list
areas_copy = areas[:]
print(
"Updated areas:", areas)

Output

['Liz', 1.65]
[
'Emma', 1.7]
11.25
9.5
Downstairs: [
'hallway', 11.25, 'kitchen', 18.0, 'living room', 20.0]
Upstairs: [
'bedroom', 10.75, 'bathroom', 9.5]
Updated areas: [
'hallway', 11.25, 'kitchen', 18.0, 'chill zone', 20.0, 'bedroom', 10.75, 'bathroom', 10.5, 'poolhouse', 'garage']

4. Functions & Methods

Functions = “do this thing.” Methods = “do this thing but for this object.”

# Functions
print(len(areas))
# list length
print(max([1.79, 1.65, 1.80]))
# largest value
print(round(1.68, 1))
# rounding
tallest = max([1.79, 1.65, 1.80])
# Methods
place =
"poolhouse"
print(place.upper())
print(place.count(
"o"))
print(areas.index(20.0))
print(areas.count(18.0))
areas.append(15.45)
areas.reverse()
print(
"Reversed areas:", areas)

Output

10
1.8
1.7
POOLHOUSE
3
5
1
Reversed areas: [15.45,
'garage', 'poolhouse', 10.5, 'bathroom', 10.75, 'bedroom', 20.0, 'chill zone', 18.0, 'kitchen', 11.25, 'hallway']

5. Packages & Imports

Packages = extra powers. Suddenly you’re a wizard.

import math
C = 2 0.43 math.pi
A = math.pi 0.43 * 2
print(
"Circumference:", C)
print(
"Area:", A)

from math import pi
C2 = 2 0.43 pi
A2 = pi 0.43 * 2
print(
"Circumference:", C2)
print(
"Area:", A2)

Output

Circumference: 2.701769682087222
Area: 0.5808804816487527
Circumference: 2.701769682087222
Area: 0.5808804816487527

6. NumPy Basics & Element-wise Operations

NumPy = when numbers refuse to behave, force them.

import numpy as np
# 1D arrays
height_in = [65, 70, 75, 80]
weight_lb = [150, 180, 210, 160]
np_height_in = np.array(height_in)
np_weight_lb = np.array(weight_lb)
print(
"NumPy array:", np_height_in)
print(
"Type:", type(np_height_in))
# Convert height to meters
np_height_m = np_height_in 0.0254
print(
"Height in meters:", np_height_m)
# 2D arrays
baseball = [[180, 78.4], [215, 102.7], [210, 98.5], [188, 75.2]]
np_baseball = np.array(baseball)
print(
"2D array shape:", np_baseball.shape)
# Subsetting
print(
"First row:", np_baseball[0])
print(
"Second column:", np_baseball[:,1])
print(
"Height of 3rd player:", np_baseball[2,0])
# Element-wise operations
conversion = np.array([0.0254, 0.453592])
result = np_baseball conversion
print(
"Converted array:\n", result)

Output

NumPy array: [65 70 75 80]
Type: <
class 'numpy.ndarray'>
Height in meters: [1.651 1.778 1.905 2.032]
2D array shape: (4, 2)
First row: [180. 78.4]
Second column: [ 78.4 102.7 98.5 75.2]
Height of 3rd player: 210.0
Converted array:
[[ 4.572 35.5616128]
[ 5.461 46.5838984]
[ 5.334 44.678812 ]
[ 4.7752 34.1101184]]

7. NumPy Statistics

print("Mean height:", np.mean(np_baseball[:,0]))
print("Median height:", np.median(np_baseball[:,0]))
print("Std dev of height:", np.std(np_baseball[:,0]))
print("Correlation coefficient:\n", np.corrcoef(np_baseball[:,0], np_baseball[:,1]))

Output

Mean height: 198.25
Median height: 199.0
Std dev of height: 14.635146053251399
Correlation coefficient:
[[1. 0.95865738]
[0.95865738 1. ]]