ITM 254

Programming with Python

TU BITM · Semester 4 · BITM curriculum and programme regulation

Requirement
required
Credits
3
Study Guide
8 units available

Chapter notes

Authoritative study guide across 8 syllabus units

Open a unit to read its study notes.

Unit 1: Introduction· 3 LHs· ~4 marks

Part 1: Core Concepts (2 Marks)

  • Python Paradigm: An interpreted, high-level, dynamically typed, garbage-collected language supporting procedural, object-oriented, and functional programming.
  • Indentation Rule: Python uses whitespace indentation (4 spaces standard) rather than curly braces {} to delimit code blocks.
  • Dynamic Typing vs Strong Typing:
    • Dynamically Typed: Variable types are resolved at runtime without explicit type declarations (x = 10; x = "hello").
    • Strongly Typed: Python will not implicitly coerce incompatible types ("Age: " + 20 raises TypeError).

Part 2: Structural Frameworks (10 Marks)

Mutable vs Immutable Built-In Types

Category Types Characteristics
Immutable int, float, bool, str, tuple, frozenset Cannot modify in-place; modifications create new objects
Mutable list, dict, set In-place modification via methods (.append(), .pop(), [key]=val)

Part 3: Distinction Tables

Basis of Comparison is Operator == Operator
Mechanism Tests object identity (checks whether id(a) == id(b) in memory). Tests value/content equality.
Example [1, 2] is [1, 2] evaluates to False. [1, 2] == [1, 2] evaluates to True.

Part 4: Worked Problems & Exam Traps

Python Control Flow with elif

score = 85
if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "A-"
elif score >= 70:
    grade = "B+"
else:
    grade = "F"
print(f"Grade: {grade}")

Mixing tabs and spaces for indentation triggers IndentationError: unindent does not match any outer indentation level. Always use 4 consistent spaces.