| PCEP SURVIVAL WALL | ANDY'S EDITION V2.0 |
1. Python Object HierarchyVALUE TYPES ├── IMMUTABLE (Cannot change value in-place) │ ├── int ──> 42, -5, 0o12 (Octal), 0x2A (Hex) │ ├── float ──> 3.14, -0.0, 2e3 (= 2000.0) │ ├── bool ──> True, False [True == 1, False == 0] │ ├── str ──> "Andy", 'PCEP', \"\"\"Multi-line\"\"\" │ └── tuple ──> (1, 2), (5,) [🚨 Needs trailing comma!] └── MUTABLE (Can change value in-place) ├── list ──> [1, 2, 3], ['x', 'y'] ├── dict ──> {"key": "value"}, {1: "one"} └── set ──> {1, 2, 3} └── SPECIAL └── None ──> None (Absence of value)
🚨 Exam Data Type Disguises
Literals containing a dot or exponent are always
floats (e.g. 1. or 2e0 are floats, not ints). Modifying an immutable tuple item directly via index (t[0] = 1) causes a TypeError.
2. Variable / Value Assignment Decoderx = 42
💥 Variable ≠ Value
Changing a variable (
x = 20) does not change the initial value object (42); it just reassigns the name label to point somewhere else.
|
3. Function Anatomy Decoder[ DEFINITION SIGNATURE ] def add ( a , b ) : │ │ └───┬───┘ │ │ └─ PARAMETERS (Placeholders inside signature) │ └─ FUNCTION NAME (Identifier) └─ KEYWORD (Starts block definition) return a + b │ ──┬── │ └─ EXPRESSION (Evaluates to a value) └─ KEYWORD (Exits function, sends value back) [ CALL & ASSIGNMENT ] result = add ( 2 , 3 ) │ │ │ ──┬── │ │ │ └─ ARGUMENTS (Actual values passed to call) │ │ └─ FUNCTION CALL │ └─ ASSIGNMENT OPERATOR └─ VARIABLE (Receives return value)
🔄 Visual Call Flow Trace
1. Code hits:
result = add(2, 3)2. Arguments map to parameters → a=2, b=3.3. Expression runs: 2 + 3 evaluates to 5.4. return 5 stops function execution and sends 5 back.5. Variable result is assigned the integer value 5.
4. Parameter vs ArgumentDEFINITION BLOCK EXECUTION CALL def greet(name): greet("Andy") │ │ ▼ ▼ [ PARAMETER ] [ ARGUMENT ] Placeholder Actual Value
💡 Mnemonic: PARAMETER = PLACEHOLDER • ARGUMENT = ACTUAL VALUE
• Positional: Mapped strictly by relative order.
🔥 Positional Follows Keyword Rule
Positional arguments MUST ALWAYS precede keyword arguments inside any call statement!
print("Hi", end="", "World") → ❌ SyntaxError: positional argument follows keyword argument
|
5. String Methods Survival Box
6. Truthy vs Falsy Sector
Strictly Falsy Values Checklist:
• False • None
• 0 (int) • 0.0 (float) • "" (empty string) • [] (empty list) • {} (empty dict) • set() (empty set)
💡 Rule: Everything else is True!
Non-empty string literals evaluate to True regardless of text content value.
bool("False") → True • bool("0") → True
|
| Global Scope: Variables defined outside functions. Visible everywhere inside file. | Local Scope: Variables defined inside a function block. Visible only within that function execution context. | Shadowing: Variable assigned inside function automatically becomes local, masking global variables. Global stays 10: x=10; def f(): x=5 |
Keyword: Reserved word token with a fixed syntactical purpose (def, while, etc.). Can never be variable identifiers! |
| PCEP SURVIVAL WALL | ANDY'S EDITION V2.0 |
1. Loops Dedicated ReviewA. FOR LOOP (Loops through a sequence) for x in range(3): print(x)
Translation: FOR EACH VALUE IN A SEQUENCE → DO SOMETHING.
B. WHILE LOOP (Repeats based on condition) while x < 3:
x += 1
Translation: REPEAT AS LONG AS CONDITION IS TRUE.
C. Loop Control Commands
• break → Exits the loop completely and immediately.
• continue → Skips remaining code inside current iteration. • pass → Null placeholder instruction. Does absolutely nothing.
🚨 Infinite Loop & Update Traps
• Loops hang forever if conditional parameters never evaluate to False.
• **Exam Trap:** Forgetting to update counter variables ( x += 1) creates infinite runs.• **Exam Trap:** continue immediately skips the rest of the current loop layer code block.
|
2. range() Exploration Terminal
MANTRA: START INCLUDED ── STOP EXCLUDED
range(stop) ──> Starts at 0, steps 1. range(start, stop) ──> Explicit start, steps 1. range(start, stop, step)──> Moves by step factor.
🚨 THE ABSOLUTE STOP VAL BOUNDARY RULE
THE STOP VALUE NEVER APPEARS IN THE OUTPUT SEQUENCE.
range(1, 5) will generate up to 4. It never yields 5. If increments are impossible (range(1, 5, -1)), it yields an empty loop without throwing errors.
|
3. Data Structures Comparison Matrix
Common List Manipulation Methods:
• .append(x) → Adds item to the very end of list.
• .insert(i, x) → Adds item at specific index position. • .remove(x) → Removes first matching value. Throws error if missing! • .pop(i) → Removes and returns item at index (defaults to end).
🚨 Empty Structures & Single Item Traps
•
{} creates an empty dictionary, NOT a set!• set() is required to instantiate an empty set.• (5) evaluates as plain integer. Single item tuples require trailing commas: (5,).
|
Slicing Axiom: seq[start:stop:step] → Start included, stop excluded. "PCEP"[1:3] yields "CE". Indexing starts at 0. |
Tolerance: Out-of-bounds slices clip cleanly instead of throwing error crashes: [1, 2][0:99] safely returns [1, 2]. |
Core Helpers: len() returns element count. type() checks type classes. print() outputs strings but returns None! |
User Input: input() always captures keyboard data streams as a str string, requiring manual numeric conversions. |
| PCEP SURVIVAL WALL | ANDY'S EDITION V2.0 |
1. Precedence Ladder & Identity
Practical Priority Examples:
• 3 << 2 | 1 → Shifts first (3 × 4 = 12), then runs bitwise OR (12 | 1) → 13.
• 2 + 3 * 4 → Multiplies first (3 × 4 = 12), then adds 2 → 14.
🚨 Identity vs Parity Equality
•
== checks if values are equal. • is checks strict unique address identities.• in / not in evaluate membership existence inside sequence iterables.
2. Common PCEP Question Decoder
|
3. Bitwise Survival Matrix (4-Bit Pilot)
•
& = COMMON BITS: 1 only if BOTH bits are 1. 10 & 12 → 8.• | = ALL BITS: 1 if at least one side is 1. 10 | 12 → 14.• ^ = DIFFERENT BITS ONLY: 1 if bit states differ. 10 ^ 12 → 6.• << Left Shift: Multiply left side by 2right. 2 << 3 → 2 × 8 = 16.• >> Right Shift: Floor divide left side by 2right. 11 >> 2 → 11 // 4 = 2.
🚨 Unary Operator Asterisk Reject
Multiplication symbols (
*) are strictly binary. Running print(*5) triggers a fatal syntax block crash!
|
4. Exception Architecture Decodertry: # Code execution lines run path here. except ArithmeticError: # Catches parent groups and subclass children! except ZeroDivisionError: # 🚨 This line is dead block if placed below parent! finally: # Guaranteed line execution regardless of errors. 5. High-Frequency Core 6 Errors
|
|
• Identifier vs Value: Changing label bindings via assignment does not mutate old data inside memory structures. • Parameter vs Argument: Parameters act as labels inside definitions; arguments provide raw value inputs inside call blocks. • Print vs Return: print() shows visual outputs but evaluates to None. Only return chains active object payloads out.
|
• Finite range() Exclusions: range(5) yields 0,1,2,3,4. The stop value 5 is never generated or accessed.• Float-String roadblocks: Running int("5.5") breaks with a ValueError. Change down sequentially: int(float("5.5")).• Missing Tuple Comma: Coding x = (5) instantiates an integer. Single items require trailing commas: x = (5,).
|
• Case Sensitivities: Tokens like true or none are valid variable labels. Only True, False, and None are keywords.• Default Parameter Constraints: Preset positional parameters ( def f(a, b=2):) must sit strictly behind raw variable placeholders.• Bitwise vs Logical: and/or short-circuit boolean valuations. &/| evaluate individual bits step-by-step.
|