liveBook · Manning

Atomic type

As explained in Get Programming: Learn to code with Python

An object type treated as indivisible because it cannot be separated into smaller object types.

An atomic type is an object type that cannot be separated into smaller object types. In Python, integers, floats, and Booleans are atomic. They are basic building blocks for values and for more complex objects. section 30.1

One value or a collection?

Consider `age = 30` and `ages = [30, 31]`. The integer `30` is atomic: it is not made up of smaller objects. The list is not atomic: it contains integer objects. Can you spot another atomic value in `[True, False]`? Both items are Booleans. section 30.1

“Built-in” and “atomic” do not mean the same thing. Strings, tuples, lists, and dictionaries are built into Python, but they are nonatomic because they can be broken down into other objects. Every object type has properties and operations you can use with it; being atomic does not mean an object has no operations. section 30.1 section 4.2

Why does the distinction help? Imagine keeping a grocery list with a separate string variable for every item. A list groups the items instead, making the code easier to organize. You can build your own object types in a similar spirit: choose the properties and behaviors they need, using existing objects as their parts. section 30.1 section 31.0

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines atomicity and classifies familiar Python types, then contrasts them with decomposable types without examining their implementation.
Examples
Uses a list of integers and a grocery-list scenario to contrast individual values with grouped objects.
What it assumes
Builds on variables and familiar Python object types while defining objects through their values and operations from the start.
What you can do after
Evaluate/understand whether a familiar Python type is atomic and when grouping values into another object type makes code clearer.
How it connects
Connects atomic types to built-in types, lists, dictionaries, and classes that package properties and behaviors.

Also explained in

Compare how 17 books explain atomic type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.