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
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
How computer represent (= interpret)
characters (text)
How computer represent (= interpret)
boolean values
❮
❯