A structured memory-map for Python fundamentals: variables, operators, flow control, data structures, functions, file operations, exceptions, modules, and object-oriented thinking.
Python fundamentals can be organized as a small number of recurring structures. Instead of memorizing isolated syntax, build a map: state representation → logic control → information organization → abstraction → robustness → persistence → system modeling.
A Python program stores information, makes decisions, repeats actions, organizes data, packages reusable logic, handles failures, reads/writes files, and eventually models systems with objects.
Variables and types represent information.
Operators, conditions, and loops control execution.
Lists, dictionaries, tuples, sets, and strings organize data.
Functions and modules package repeated logic.
Exceptions prevent one error from collapsing the whole program.
Classes and objects model entities with attributes and behavior.
Variables attach names to values. Data types define what operations are meaningful for those values.
x = 10 # int
ratio = 3.14 # float
name = "Python" # str
items = [1, 2, 3] # list
point = (1, 2) # tuple
info = {"id": 7} # dict
unique = {1, 2, 3} # set| Type | Example | Intuition |
|---|---|---|
| int / float | 10, 3.14 | Numbers for counting and continuous values. |
| str | "abc" | Text sequence. |
| list | [1,2,3] | Ordered, mutable collection. |
| tuple | (1,2) | Ordered, usually fixed collection. |
| dict | {"key": "value"} | Key-value lookup table. |
| set | {1,2,3} | Unique unordered collection. |
Operators are the small logic blocks that transform or compare values.
| Category | Operators | Meaning |
|---|---|---|
| Arithmetic | + - * / // % ** | Add, subtract, multiply, divide, integer divide, remainder, power. |
| Comparison | == != > < >= <= | Produce True / False decisions. |
| Logic | and or not | Combine Boolean conditions. |
| Membership | in, not in | Check whether a value is inside a container. |
price = 2800
distance = 3.2
is_good = price < 3000 and distance < 5
print(is_good)Flow control decides which code runs and how many times it runs.
if condition:
do_this()
elif another_condition:
do_that()
else:
do_default()for item in items:
print(item)
while condition:
keep_running()break exits the loop. continue skips the current iteration and moves to the next one.
Ordered, mutable collection. Good for sequences.
nums = [1, 2, 3]
nums.append(4)
nums.insert(0, 0)
nums.remove(2)
nums.sort()Key-value structure. Good for lookup and labeled data.
person = {"name": "Ada", "age": 30}
print(person["name"])
print(person.get("city", "unknown"))
person["age"] = 31
del person["age"]| Structure | Best use | Common methods |
|---|---|---|
| list | Ordered changing sequence | append, insert, pop, sort |
| dict | Named lookup table | get, keys, values, items |
| str | Text processing | split, join, strip, replace |
| set | Unique values | add, remove, union/intersection |
| tuple | Fixed grouped values | indexing, unpacking |
A function packages repeated logic into a reusable block.
def function_name(param1, param2="default"):
"""Explain what the function does."""
result = param1 + param2
return result| Concept | Pattern | Meaning |
|---|---|---|
| Call | name(args) | Use a function. |
| Positional argument | f(1,2) | Arguments matched by order. |
| Keyword argument | f(x=1) | Arguments matched by name. |
| Default argument | def f(x=0) | Use default if not provided. |
| *args | def f(*args) | Accept many positional arguments. |
| **kwargs | def f(**kwargs) | Accept many keyword arguments. |
| lambda | lambda x: x+1 | Small unnamed one-line function. |
Files allow information to survive after the program stops.
| Mode | Meaning |
|---|---|
r | Read |
w | Write and overwrite |
a | Append |
b | Binary mode |
with open("data.txt", "r") as f:
text = f.read()
with open("out.txt", "w") as f:
f.write("hello")Exception handling prevents one local failure from crashing the entire system.
try:
result = risky_operation()
except ValueError:
handle_bad_value()
else:
run_if_no_error()
finally:
always_cleanup()Use exceptions to isolate risk: file missing, bad input, network failure, conversion error, or unexpected data format.
Modules organize functions, classes, and constants into reusable files or packages.
| Pattern | Meaning | Comment |
|---|---|---|
import module | Import whole module | Clear namespace. |
import module as m | Import with alias | Common for long names. |
from module import function | Import one item | Convenient but less explicit. |
from module import * | Import everything | Usually not recommended. |
import math
import pandas as pd
from pathlib import PathOOP models an entity as data plus behavior.
| Term | Meaning |
|---|---|
| Class | Blueprint. |
| Object | Concrete instance of a class. |
| Attribute | Object feature / stored state. |
| Method | Object behavior. |
| Inheritance | Child class receives parent behavior. |
| Polymorphism | Different classes implement same method differently. |
class Device:
def __init__(self, name, voltage):
self.name = name
self.voltage = voltage
def describe(self):
return f"{self.name}: {self.voltage} V"
d = Device("LDMOS", 12)
print(d.describe())| Function | Use | Memory anchor |
|---|---|---|
print() | Output | Show information. |
input() | Input | Receive user text. |
len() | Length | Count elements. |
type() | Type check | Inspect what something is. |
int(), str(), float() | Conversion | Change representation. |
range() | Number sequence | Loop counter source. |
enumerate() | Index + value | Track position while looping. |
zip() | Pair items | Walk two lists together. |
max(), min(), sum() | Aggregation | Summarize values. |
sorted() | New sorted list | Sort without modifying original. |
map() | Apply function | Transform each element. |
filter() | Keep matching values | Select by condition. |
open() | File access | Read or write files. |
Create variables for name, price, distance, and tags. Print their types.
Use if to classify a candidate as good if price and distance pass thresholds.
Store several candidates as dictionaries inside a list, then loop through them.
Write a function that calculates a score from price and distance.
Write results into a text file using with open(...).
Add try/except around number conversion from user input.
Click each card to reveal the answer.
A name referring to a value.
The category of a value, such as int, str, list, or dict.
A True/False expression used to choose a path.
A repeated execution structure.
An ordered mutable collection.
A key-value mapping.
A reusable block of logic.
A reusable Python file or package.
A runtime error event that can be handled.
A blueprint for objects.
A concrete instance of a class.
A function attached to an object.
Once this map is stable, advanced tools such as Pandas, Matplotlib, automation, and machine learning become easier to learn because they all reuse the same foundations.