Values

- Value = the "worth" of something Values are fundamental representations of data/information inside a computer program Computer programs operate/manipulate/transform values ! Example of values:
        1               an integer number
        3.14		  an floating point number
        "Hello"         a text/string with 5 letters
        True            a logical value

Data types

- Every value has a (data) type Examples:
         Value       Python Data type
        ==============================
           1            int           the whole numbers
           3.14         float         the real numbers
           "Hello"      string        text
           True         boolean       logical values (True/False)
- Command to find the type of a value:
            type(value)

      >>> type(4)
      <class 'int'>
      >>> type("Hello")
      <class 'str'>

Exercise

- What is the type of the following values:
        type(1)

        type("1")

        type(3.14)

        type("3.14)

        type(True)

        type("True")

        type('True')

Exercise

- What is the type of the following values: (Answers):
        type(1)                  integer

        type("1")		   string !

        type(3.14)		   float

        type("3.14)		   string !

        type(True)		   boolean

        type("True")		   string !

        type('True')		   string ! (single quote works too)

The special value `None` in Python

- The special value denoted by:
            None
- is used to denote/represent no value The data type of `None` is: `NoneType`
      >>> type(None)
      <class 'NoneType'>
- Note:
  `None` is not the same as the integer 0 ! `None` is not the same as the empty string "" !

Why do we need a type for a value ?

- Recall that we can only store numbers (= values) inside the computer (memory): The data type provides the context on how to interpret the number (value) Key to understand information:
  Information = data (=value) + context (interprete data)

How computer represent (= interpret) integer values

- Recall: computer can store integer numbers: How computers represent integer values:
  Integer values are represented naively (= straightforwardly) using integer numbers inside a computer

How computer represent (= interpret) floating point values

- A floating point value consists of 2 parts:
        (1) A  mantissa
        (2) An exponent

        Example:     123.45678   =   0.12345678 × 103

        Mantissa = 12345678      Exponent = 3
- How computers represent floating point values:
  Floating point values are represented using 2 integers An integer that represents the mantissa An integer that represents the exponent
(I.e.: we need to know the type of a value in order to know how we must interpret the integer number(s) !)

How computer represent (= interpret) characters (text)

- A text is a string of letters/symbols from som alphabet Each letter/symbol of the alphabet is encoded by a unique integer value The universal code used to represent all symbols in the world's lamguages is the Unicode: Examples:
       English   Character code    Other    Character code
       ========================    ==========================
         A           65             α       945  (Greek)
         B           66	      א      (1488-Hebrew)
         a	       97	      花      33457 (Chinese)
         b	       98
         0           48
         1	       49
(One more example that shows that we need to know the type of a value in order to know how we must interpret the integer number(s) !)

How computer represent (= interpret) boolean values

- There are only 2 boolean values:
  `True` `False`
- How computers represent boolean values:
       False:       the number 0
       True:        any number other than 0
(One more example that shows that we need to know the type of a value in order to know how we must interpret the integer number(s) !)

❮ ❯