Skip to main content
Chemistry LibreTexts

2.1: Introduction to Data Types

  • Page ID
    430736
  • \( \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}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

     

    What is data?

    To the chemist data are the measured or counted values that can be collected or produced to understand relationships of observable or computed phenomena that are germane to the practice of science (both empirical and computational).  To the chemist there are different types of data that are defined by how the data is generated, like the mass or temperature of a sample, or the spectra of a compound.  This data is often stored on a computer in a file or database, and can be subsequently processed through various software programs.

    To the computer scientist or software program data has a different meaning in that there are different data types that represent how the computer stores information.  That is, a computer does not store a measured phenomena like the temperature of a sample, but a digital data type, a representation of the temperature that a software agent can interact with.  For example, a letter of the alphabet would be a different type of data than a number, because you can not do arithmetic calculations on letters like you do on numbers. These different ways of representing information are data types.

    We need to understand both meanings of the concept of data, and in this section we will learn how computers store data, and the different types of data from the perspective of programming and software agents.  

    What is a database?

    Databases are a way computers store information in a manner that can be retrieved.  You use databases all the time.  Do you realize that as you read this web page you are using a database?  Yes, this web page is not a digital file like a MS Word document that saves the information like a sheet of paper, but instead the web browser is displaying information that was pulled from a database as the page is loaded.  That is, LibreText is a Wiki that is hosted on the MindTouch knowledge management platform and the information you see is drawn from a database when the page is loaded.  Webpages that are pulled from databases are often called dynamic web content, and those that are files are called static web content. Of course, databases can store different types of information, and this class will be using databases that store information related to chemical compounds.  But it is important to realize that the use of databases in the twentieth century are pervasive, and you are actually using a database right now, as you read this webpage.

    How do databases store information?

    Databases store data, which is the representation of information through a binary code that computing machines can read. A bit is the smallest binary value with two possibilities, 0 or 1.  This data needs to be stored on a physical medium so the machine can read it.  In the old days data was stored on punch cards (figure 1.3.1), which allowed for a binary representation of each position, which could be either punched or not punched (bitten or not bitten).  If each location of memory is allowed a certain number of bits, then you can generate different combinations, and give those different combinations different meanings.

    clipboard_eff49d0aacece37b3ab4dfbbff419867a.png
    Figure \(\PageIndex{1}\): 5081 data processing card containing a line of DOS JCL code. The code reads: //STEP2 EXEC PROC=SLINK,TESTPGM=DADK,ACCT=DADKThe (CC BY-SA; Dick Kutz at English Wikipedia)

     

    clipboard_e224f268035576408fa2699de9a693d12.png
    Figure \(\PageIndex{2}\): Old Fortran punch card, one of the earliest computer based means for storing data (CC BY-SA; Arnold Reinhold)

     

    A quick look at these possibilities shows that n bits gives 2n possible combinations.

    • 1 bit has two (21)possibilities : 0 or 1, and so can represent two different things
    • 2 bits has four (22) possibilities: 00, 01, 10, or 11, and so can represent four different things
    • 3 bits has 8 (23) possibilities: 001, 010, 100, 011, 101, 101, 110, 111, and so can represent 8 different things.
    • 8 bits has 8 (28) possibilities, which is 128, ranging from 00000000 to 11111111, and we won't write them all down here.
    • n bits has (2n)

    A byte of data is defined as 8 bits and so has (28) or 128 values (which run for 0 to 127).

    How a hard drive works?

     

    The take home message here is that everything is stored on the computer in the form of a binary bit, be it a text document, picture, molecular structure data or a spectral file.  Each of these represent a different data type and so when you interact with the database, you need to know what type of data is stored, and then use software that can "read" that type of data.  Likewise, if you write some simple script to interact with data, you need to recognize the data type you are interacting with, for example, you can do math with numbers, but not letters, and so a number needs to be a different data type than a letter.

    Today we do not use punch cards but still store data as a binary representation on a physical device that can be electronically read, like magnetic tape, hard drives, flash drives, SSD (Solid State Disk) and the like.  The way magnetic based storage devices work is through the North-South alignment of the magnetic field, where one of these (N-S) would be given the value of 1, and the other (S-N) would be the 0.  If you are interested in learning how a hard drive works there is a real good 6 minute video on Nick Parlante's computer science page from Stanford.  Flash drives and SSDs have no moving parts and are not based on magnetism, but represent ones and zeros by the ability of tiny channels (gates) within a transistor to be able to conduct (1) or not conduct (0) electricity.  It should be noted that after 10-20 years flash drives can lose their memory.  In fact, surprisingly magnetic tape is the longest lasting digital storage, although it is the slowest to use.

     

    What is a Data Type?

    If you store some data on a computer it must have a data type, which allows python to know how to read it. In Python there are two different types of Data Type (no pun intended), those of a single character, and those with multiple characters. These data types are actually a type of object in Python called a class, and each class has different attributes and methods (functions) associated with it.  For example the number "1" as an interger, when added to itself, gives 2, but the number "1" as a letter (string), gives 11 when added to itself.  In the box below we define two variables for the value of one.  If we print the output of the type command, we can see what type of data each value is, and as we shall see, 1 is stored differently on the computer than 1.0.

    x=1
    y=1.0
    print(type(x))
    print(type(y))
    Hello world!

     Note, python treats "letters" as a single character of the string data type, and I have chosen to put it in both places of the following table, which might not be correct, but makes sense to me.

    Single Character (atomic) Data Types

    Name Python type Description
    Integer Int Whole Number
    Floating point float

    Decimal point numbers

    Boolean bool True or False logical values
    Strings  str single character (this is really a string of length one)

    Container (Multiple Character Data) Types

    Name Python type Description
    Strings str

    ordered immutable string of characters (a sentence is a string)

    List list unordered mutable sequence of objects [10, "10", 10.0] 
    Dictionary dict unordered Key:Value pair {k1:v1, k2:v2}
    Tuple tup ordered immutable sequence of objects (10, "10", 10.0)
    Set set unordered group of unique objects {'a','b'}

    note

    • ordered means it can not switch its position, like the order of the elements in the periodic table, carbon is always 6.
    • unordered means any order can occur
    • mutable means a value can change, like the mass of a person can change over time and thus mutable
    •  immutable means a value can not change, like the atomic mass of an isotope of hydrogen is a constant and immutable.

     

    Tutorials

     


    This page titled 2.1: Introduction to Data Types is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?