IT FundamentalsPCAPPCEP

Python PCAP/PCEP: Core Programming, Data Structures, and Object-Oriented Concepts

Python is the most popular programming language in the world for good reason: its clean syntax lowers the barrier to entry without sacrificing power. The Python Institute offers two certification levels — PCEP (Python Certified Entry-Level Programmer) tests absolute fundamentals, while PCAP (Python Certified Associate Programmer) adds object-oriented programming, exception handling, modules, and file I/O. Whether you are starting your programming journey or formalising skills you already use, this guide covers the concepts that both exams test most heavily.

13 min
5 sections · 10 exam key points

Python Fundamentals: Variables, Types, and Operators

Python is dynamically typed — you do not declare variable types. Python infers them at runtime. Built-in types: int (whole numbers, arbitrary precision), float (decimal — IEEE 754 double precision, be careful with floating-point arithmetic: 0.1 + 0.2 != 0.3), str (immutable sequence of Unicode characters), bool (True or False — subclass of int: True == 1, False == 0), NoneType (the None object — Python's null value). Type conversion: int('42') converts string to int, str(42) converts int to string, float('3.14') converts string to float. Operators: arithmetic (+, -, *, /, // floor division, % modulo, ** exponentiation), comparison (==, !=, <, >, <=, >= — return bool), logical (and, or, not — short-circuit evaluation), identity (is, is not — tests object identity, not equality — is None is the correct way to check for None), membership (in, not in — tests for membership in a sequence or collection). String operations: concatenation with +, repetition with *, indexing (s[0] = first char, s[-1] = last char), slicing (s[1:4] = chars 1, 2, 3 — end index is exclusive), len(), lower(), upper(), strip(), split(), join(), format(), f-strings (f'Hello {name}!').

Control Flow and Functions

Python uses indentation (not braces) to define code blocks — consistent indentation is syntactically required. Control flow: if / elif / else (Python has no switch statement — use if/elif chains or dictionaries for dispatch), for loops (iterate over any iterable — for item in list, for i in range(10)), while loops (continue while condition is True), break (exit the loop immediately), continue (skip to next iteration), else on for/while (runs if loop completes without hitting break — often surprising to newcomers). Functions: defined with def keyword, return a value with return (implicit return of None if no return statement). Default parameters (def greet(name='World'): — mutable default arguments like lists are a classic bug, use None as default and create the list inside), *args (variable positional arguments as a tuple), **kwargs (variable keyword arguments as a dict). Lambda functions: anonymous one-line functions — lambda x: x * 2 — useful for sort keys and functional programming patterns. List comprehensions: [x**2 for x in range(10) if x % 2 == 0] — creates a list, faster and more Pythonic than equivalent for-loop.

Data Structures: Lists, Tuples, Dicts, and Sets

Python's four main collection types each serve a different purpose. Lists (mutable, ordered, allow duplicates): my_list = [1, 2, 3]. Methods: append(), extend(), insert(), remove(), pop(), sort(), reverse(), index(). Lists are passed by reference — modifying a list inside a function modifies the original. Tuples (immutable, ordered, allow duplicates): my_tuple = (1, 2, 3). Use tuples for fixed data (coordinates, RGB values), as dictionary keys (lists cannot be dict keys), and for multiple return values. Dictionaries (mutable, key-value pairs, keys are unique): my_dict = {'key': 'value'}. Access: dict['key'] (raises KeyError if missing), dict.get('key', default) (safe access). Methods: keys(), values(), items(), update(), pop(). Iteration: for key, value in dict.items(). Sets (mutable, unordered, unique elements): my_set = {1, 2, 3}. Operations: union (|), intersection (&), difference (-), symmetric difference (^). Use sets for membership testing (O(1) lookup) and removing duplicates from a list (list(set(my_list))).

Object-Oriented Programming in Python

OOP in Python (PCAP-level): define classes with class keyword, create objects with the class as a constructor. __init__ is the initialiser (not strictly a constructor — the object is already created when __init__ runs). self refers to the instance — must be the first parameter of every instance method. Instance variables (set on self — unique per object), class variables (set on the class — shared by all instances). Inheritance: class Dog(Animal): inherits all attributes and methods of Animal, can override methods. super() calls the parent class method. Multiple inheritance is supported — Method Resolution Order (MRO) uses C3 linearisation. Magic methods (dunder methods): __str__ (string representation — used by print()), __repr__ (developer representation — used in REPL), __len__ (len() support), __eq__ (equality with ==), __lt__ (less-than for sorting), __add__ (+ operator overloading). Encapsulation conventions: _name (single underscore — convention for 'internal', not enforced), __name (double underscore — name mangling, makes attribute harder to access accidentally from outside the class).

Exception Handling, Modules, and File I/O

Exception handling: try / except / else / finally. except catches specific exceptions (except ValueError, except (TypeError, KeyError)). else block runs if no exception was raised. finally runs always — used for cleanup (close file, release lock). raise re-raises the current exception or raises a new one. Custom exceptions: class MyError(Exception): pass — inherit from Exception or a specific exception class. Common exceptions to know: ValueError (invalid value — int('abc')), TypeError (wrong type — 1 + '2'), KeyError (missing dict key), IndexError (list index out of range), FileNotFoundError (file does not exist), AttributeError (object has no such attribute), ImportError (module not found). Modules: import module (use as module.function()), from module import function (use as function() directly), import module as alias. The if __name__ == '__main__': guard prevents code from running when the module is imported. File I/O: open(path, mode) — modes: 'r' (read), 'w' (write, creates/truncates), 'a' (append), 'b' (binary). Use with open(path) as f: context manager — automatically closes file even if an exception occurs. f.read(), f.readline(), f.readlines(), f.write(). JSON: import json; json.dumps(obj) serialises to string, json.loads(string) deserialises to Python object, json.dump(obj, file) writes to file, json.load(file) reads from file.

Key exam facts — PCAP / PCEP

  • Python is dynamically typed — no type declarations, types are inferred at runtime
  • is checks identity (same object); == checks equality (same value) — use 'is None', not '== None'
  • Mutable default arguments (def f(x=[])) are shared across calls — use None and create inside function
  • List comprehension: [expr for item in iterable if condition] — Pythonic and fast
  • Tuple is immutable; list is mutable — tuples can be dict keys, lists cannot
  • Dictionary .get(key, default) is safe; dict[key] raises KeyError if missing
  • __str__ is for print(); __repr__ is for REPL and debugging
  • finally block always runs — use for cleanup regardless of exception
  • with open(path) as f: context manager automatically closes file on exit
  • if __name__ == '__main__': guard prevents execution when module is imported

Common exam traps

Python is only suitable for scripts and data science

Python powers web frameworks (Django, FastAPI), machine learning (TensorFlow, PyTorch), DevOps tooling (Ansible, AWS SDK), networking automation (Netmiko, NAPALM), and systems automation at scale. It is a general-purpose language.

Variables in Python store values

Python variables are references (pointers) to objects. When you write x = [1, 2, 3] and then y = x, both x and y reference the same list. Modifying through y also modifies what x sees — to get a copy, use y = x.copy() or y = x[:].

Exceptions should be caught broadly with except Exception:

Broad exception catching hides bugs and makes debugging harder. Catch the specific exceptions you expect and can handle. Let unexpected exceptions propagate — they reveal bugs that would otherwise be silent.

Practice this topic

Test yourself on Python Programming

JT Exams routes you to questions in your exact weak areas — automatically, after every session.

No credit card · Cancel anytime

Related certification topics