DDMA Level IIIPython Data Visualisation
Chapters
Chapters0 of 7 readSign in to track progress
Chapter 1

Part A: Python foundations

The Python language

Last updated November 2026about 4 min read

Key takeaways

  • Python is a high-level, interpreted language whose readable syntax and large ecosystem of data-focused libraries have made it the dominant language for data science work.
  • Keywords such as if, for and def are reserved words with a fixed meaning; identifiers are the names a programmer chooses for variables and functions.
  • Python uses indentation, not braces, to define blocks of code, so an inconsistently indented block is a syntax error, not just a style problem.
  • A backslash at the end of a line continues a statement onto the next, statements inside brackets can span lines without one, and PEP 8 is the standard style guide.
  • For data acquisition, scrapy builds web scrapers that extract data from websites at scale, while BeautifulSoup parses HTML and XML to pull specific data from a single page.

Python is a high-level, interpreted programming language (Introduction to Computing Systems, in the chapter on computer software), whose readable syntax and large ecosystem of data-focused libraries have made it the dominant language for data science work.

Description of the Python language, the basic vocabulary every program is built from:

Python version, packages and datasets
Python 3 is the current standard; packages extend the language, and a dataset is the data a program works with.
Keywords and identifiers
Keywords are reserved words with fixed meaning (if, for, def); identifiers are the names a programmer chooses for variables and functions.
Statements and comments
A statement is an instruction Python executes; a comment (starting with #) is ignored by Python, left for human readers.
Data types and variables
A variable holds a value of a given data type, int, float, str, bool, list, dict and others.
Type conversion
Explicitly converting a value from one data type to another, e.g. int('5') to convert text to a whole number.
Input/output and import
input() reads user input, print() writes output, and import brings in a library's functionality.
Arithmetic operators and loops
+, -, *, /, // and % perform calculations; for and while loops repeat a block of code.

Python syntax:

Script mode programming
Writing a full program in a .py file and running it, rather than typing commands one at a time.
Python line structure
Python uses indentation, not braces, to define blocks of code, so consistent indentation is not optional.
Joining two lines
A backslash (\) at the end of a line continues a statement onto the next line.
Multi-line statements and indentation
Statements can span multiple lines inside brackets without a backslash; indentation still defines each block's scope.
Python coding style
PEP 8 is Python's standard style guide, consistent naming, spacing and line length, for code that is easy for others to read.

A Python library is a reusable collection of pre-written functions and classes, saving a programmer from writing common functionality from scratch.

Python libraries for data science, starting with data acquisition:

scrapy
A framework for building web scrapers that extract data from websites at scale.
BeautifulSoup
A library for parsing HTML and XML, commonly used to extract specific data from a single scraped page.

Exam tip

Python's indentation-defines-blocks rule (rather than braces or keywords like 'end') is a frequently tested distinguishing feature versus other languages, an inconsistently indented block is a syntax error in Python, not just a style problem.

Test Your Knowledge

3 questions on this chapter
Question 1 of 3A data clerk at a Kisumu Sacco writes an if statement in a .py script but indents the lines inside its block inconsistently. What happens when the script runs?
Pick an option first
Question 2 of 3An analyst needs to build a scraper that extracts price data from many retail websites at scale. Which library does the chapter name for that job?
Pick an option first
Question 3 of 3A program reads a quantity as the text '5' and the programmer writes int('5') to turn it into a whole number. What is this called?
Pick an option first