[Tutor] Fwd: Difference between types

Citizen Kant citizenkant at gmail.com
Fri May 24 13:04:45 CEST 2013


Are you referring to this definition?

http://en.wikipedia.org/wiki/**Value_%28computer_science%29<http://en.wikipedia.org/wiki/Value_%28computer_science%29>

As far as it goes, that's not an unreasonable rule of thumb, but it isn't
bullet-proof. What, for example, do you make of this:

0x09

Is that a value? I say yes, because that is a literal expression for the
natural number 9. It merely happens to use hexadecimal notation instead of
decimal notation. Another language might define keywords one, two, three
... nine, ten which are also literal expressions for the same natural
number, only using English words instead of numerals.

But let's not worry about hypothetical languages with such keywords. Even
in Python, each of these represent the exact same value:

9 0x09 0o10 0b1001

They are the same value, using different notation.

I'm referring to that definition. I've found out that, unless for me, it's
useful to think Python in this line. That leads me to think, first, that
every single character is in itself a value, any single thing that one can
find inside a Python script is somehow value, all are characters. So, since
Python only (is this correct?) works with values, then came the question
about how to create different kinds of value, so to speak more complex,
that respond to value's definition. The answer I've managed to give to
myself is that this could be accomplished by: setting a rule that makes
whatever to "have the shape" of a value. That's to say, for example:
'apostrophes' act as the shape of a value named string, no matter what one
puts inside it. So 'apostrophes' are just a label that Python considers the
shape of a value. Same happens with the tuple (100, 'value', 2);  where
parenthesis and semi colon work as a rule, setting the shape of a value
named tuple that's different to the shape of a value named list. At the
same time both shapes are equal (since both are value).

As far as I can think, the same must happen with all the other types of
value in Python.

Then, something like my_variable doesn't respond to value's definition
(even if no one can say that doesn't "look like" a normal form) until a
value it's assigned to it. Then
if my_variable = 9
<type 'int'>
if my_variable = 'A'
the <type 'str'>

I'm not very strong in maths, so I can't tell what's going on with 0x09.
Could it be that simple as that anything between integers is int, and
that's why one cannot start a variable name with a number since a
variable's name starting with a number could be perfectly confused with
some integer?

The point is, given this Python environment, would it be correct to look
for some truth, asking to myself "in which way every single thing in Python
comes to be a value (following value's wikipedia definition)?

Anyway, this line of thinking doesn't lead me to understand where's the
label for a value (acting as operator) like + or - or * for example. I
simply tend to think that maybe the difference is so to speak built-in in
Python.


Likewise for every object. Compound objects are also values:

iter([12, 3, None, "hello world!", 4.5, ('a', 'b', 3), {}])

It looks that your example match with the idea I've presented above. Am I
right? The fact that you wrote {} , looks like the pair of { } itself is
the value that one can always fill with some other proper value if it's
necessary.

 type('A')
> <type 'str'>
>
> The question is, in order to understand: does this apostrophes thing has a
> more profound reason to be attached to the letters or it's just a
> conventional way to set a difference between letters and numbers?
>

The later. It is a long standing tradition in computer programming that
so-called "strings" (ordered sequences of letters, digits and other
characters) are defined using a notation that includes quotation marks as
delimiters. In contrast, numbers are written in straight numeric form,
usually in base-10 but sometimes in other bases.

I guess that "delimiter" sound perfect to name what I use to see as the
shape or skin of values: 'delimiters' [delimiters] {delimiters}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130524/8c4e211f/attachment.html>


More information about the Tutor mailing list