A value is one of the fundamental things — like a word or a number — that a program manipulates. Some values are 5
(the result when we add 2 + 3
), and "Hello, World!"
. These objects are classified into different classes, or data types: 4 is an integer, and “Hello, World!” is a string, so-called because it contains a string or sequence of letters. You (and the interpreter) can identify strings because they are enclosed in quotation marks.
"Hello, World!"
is a string value, which is shown as str
in Python. A string is any sequence of numbers, letters, and punctuation.35
is an integer value, which is shown as int
in Python. An integer just means a whole number; for example, 42, -12, and 0 are integers.34.25
is a float which is used for storing decimal numbers. You can determine the type of an object by calling the type()
function on it.
Fork the code below and run it to see the output.
You can usually mix float
values with int
values, and the result will be another float
.
You can also mix String
and int
, with surprising results. Fork the below code and see what happens.