Skip to content

Computer Science · Ch 5 — Getting Started with Python

Data Types

5.7

Data Types

Every value in Python belongs to a specific data type. A data type does two jobs at once: it identifies what kind of data values a variable can hold, and it determines which operations can be performed on that data. An integer can be divided; a string can be concatenated; a set refuses duplicates — the type is what grants and limits these abilities.

Figure 5.6 lays out the full family of data types available in Python, and the sub-sections that follow walk through each branch:

  • 5.7.1 Number — int, float and complex, plus the boolean subtype bool.
  • 5.7.2 Sequence — the ordered, integer-indexed collections: strings, lists and tuples.
  • 5.7.3 Set — an unordered collection with no duplicate entries.
  • 5.7.4 None — the special type whose single value signifies the absence of a value.
  • 5.7.5 Mapping — key-value storage; Python's one standard mapping type is the dictionary. …
Figure 5.6Different data types in Python
Fig. 5.6 — Different data types in Python

Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your NCERT textbook's own diagram.

This figure is a hierarchy (tree) diagram laying out every data type available in Python — the map for the whole of Section 5.7.

At the root sits a box labelled "Data Types in Python". From it, five branches descend, one for each top-level family:

  • Numbers — this branch splits further into Integer, Floating Point and Complex, the three numeric types of Section 5.7.1. Attached below Integer is Boolean, drawn as its child — a visual reminder that bool is a subtype of integer.
  • Sequences — branching into Strings, Lists and Tuples, the three ordered, integer-indexed collection types of Section 5.7.2.
  • Sets — the unordered, duplicate-free collection of Section 5.7.3, with no further subdivision.
  • None — the special "absence of value" type of Section 5.7.4, also a leaf on its own.
  • Mappings — leading to Dictionaries, Python's single standard mapping type (Section 5.7.5). …