Module 1 · Foundations of Python and Data Handling

Section 2: Python Basics for Data Visualization

Variables · Data Types · Lists · Dictionaries · Control Flow · Functions

🔢 Variables & Data Types
  • Strings str, integers int, floats float, booleans bool
  • Dynamic typing — no need to declare types
  • Type conversion: int(), float(), str()
  • Naming conventions: lowercase with underscores
📋 Lists & Indexing
  • Ordered, mutable collections: [1, 2, 3]
  • Zero-based indexing and negative indexing
  • Slicing: list[1:4] to extract subsets
  • Methods: append, extend, sort, len
📚 Dictionaries
  • Key-value pairs: {"name": "Alice", "sales": 5000}
  • Fast lookup by key; keys must be unique
  • Nested dicts for structured records
  • Methods: .keys(), .values(), .items()
🔀 Control Flow
  • if / elif / else for conditional logic
  • for loops to iterate over lists and dicts
  • List comprehensions: [x*2 for x in data]
  • Boolean operators: and, or, not
🔧 Functions
  • Define with def, return values with return
  • Parameters and default argument values
  • Scope: local vs. global variables
  • Reusable code blocks for data transformations
🧪 Lab 2 — Python Fundamentals Practice
  • Create lists and dictionaries for sales data
  • Write loops to compute totals and averages
  • Define functions to clean and transform data
  • Use comprehensions to filter and reshape datasets