Variables as Labels
In Python, variables aren't just boxes; they are labels (or references) that point to data living in memory.
player_name = "Alice"
score = 100
# Updating the score
score = score + 50
Logic & Decisions
Programs need to make decisions. The if statement creates a fork in the
road.
if is_raining:
print("Take an umbrella")
else:
print("Wear sunglasses")
Loops & Iteration
The for loop iterates over items
in a sequence.
for fruit in fruits:
print("I like " + fruit)
Memory Visualization
Lists & Indices
Visualizing arrays in memory. Each slot has an integer index.
my_list = ["Data", 42, True]
print(my_list[1]) # Output: 42
Sequence Diagrams
Visualize the timeline of a function call. Code is not just static text; it is an event in time.
def greet(name):
return "Hello " + name
Data Visualization
Using libraries like matplotlib
to render data.
plt.plot(x, y)
plt.show()
Recursion & Canvas
Visualizing Recursion. A function that calls itself can create complex, natural patterns like this fractal tree.
def draw_branch(len):
if len > 5:
draw_line(len)
draw_branch(len * 0.7)
3D Programming
Python is used for 3D Game Dev (Blender, Ursina). This requires thinking in X, Y, and Z coordinates.
cube = Entity(model='cube')
def update():
cube.rotation_y += 1
cube.rotation_x += 0.5
Vector Graphics (SVG)
Scalable Vector Graphics are defined by math, not pixels. This is crucial for coordinate geometry and plotting.
<svg width="200">
<circle cx="50" cy="50" />
<rect x="100" y="10" />
</svg>
Physics Simulation
Libraries like pymunk or pygame handle gravity, collisions,
and forces.
space.gravity = (0.0, -900.0)
body = Body(mass=1, moment=10)
body.position = (50, 100)
space.add(body)
Geospatial Maps
Python libraries like folium
allow you to visualize data on interactive maps using latitude and longitude.
import folium
m = folium.Map(location=[51.5, -0.09])
folium.Marker([51.5, -0.09], "Hi!").add_to(m)
Network Graphs
Complex relationships (like social networks) are visualized using nodes and edges. networkx is the Python standard.
import networkx as nx
G = nx.Graph()
G.add_edge(1, 2)
G.add_edge(1, 3)
nx.draw(G)
The Console (CLI)
Sometimes the best visual is text. The CLI (Command Line Interface) is where Python lives natively.
print("Hello World")
input("Enter command: ")
$ python3 script.py
Initializing visualization engines...
[OK] Mermaid loaded
[OK] Three.js loaded
[OK] Physics engine active
Ready for input