Skip to main content
Engineering LibreTexts

3.3: Atomic Data Types

  • Page ID
    39350
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    There’s one other thing that a variable has in addition to its name and value: a type2. In a programming language like Python, every piece of data has a specific type, which is necessary for determining how it behaves and what all you can do to it. A question you should ask yourself a lot is: “okay, I’ve got a variable in my environment called x...now what is its type?” You might have guessed (correctly) that our age and slogan variables from the previous section are of different types: one is a number, and the other is a phrase.

    In this course, we’ll principally deal with three types of atomic data, all of which will be familiar to you.

    Whole Numbers

    One very common type of data is whole numbers, or integers. These are usually positive, but can be negative, and have no decimal point. Things like a person’s birth year, a candidate’s vote total, or a social media post’s number of “likes” are represented with this data type.

    Real (fractional) Numbers

    You may remember from high school math that the so-called “real numbers” include not only integers, but also numbers with digits after the decimal point. This type can therefore be used to store interest rates, temperature readings, and average movie ratings on a 1-to-5 scale.

    Since all whole numbers are themselves real numbers, you might wonder why we bother to define two different types for these. Why not just give both kinds of variables the same real number type? Basically, the answer is that something “feels wrong” about that to the Data Science community. A Facebook user might have 240 friends, or 241, but it would never make sense for her to have 240.3 friends. A consensus has thus arisen: variables that would only ever store whole numbers really ought to be of a type that’s devoted to only whole numbers. You can violate this convention, but you’ll be thought weird by your fellow developers if you do so.

    Text

    Lastly, some values obviously aren’t numeric at all, like a customer’s name, a show title, or a tweet. So our third type of data is textual. Variables of this type have a sequence of characters as values. These characters are most often English letters, but can also include spaces, punctuation, and characters from other alphabets.

    By the way, this third data type can tiptoe right up to the “atomic” line and sometimes cross it. In other words, we will occasionally work with text values non-atomically, by splitting them up into their constituent words or even letters. Most of the time, though, we’ll treat a character sequence like "Avengers: Endgame" as a single, indivisible chunk of data in the same way we treat a number like 42.

    But What About...?

    What about other things a computer can store: images, song files, videos? It turns out that through clever tricks, all these kinds of media and more can be boiled down to a large number of integers, and stored in an aggregate data structure like those discussed in the next chapter. At the atomic level, we’ll really only ever need to deal with the three types of this section.

    2Strictly speaking, although in languages like Java variables indeed have types, in Python the values have types, not the variables. This distinction will never be important for us though.


    This page titled 3.3: Atomic Data Types is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Stephen Davies (allthemath.org) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.