[Tutor] Difference between types

Dave Angel davea at davea.name
Fri May 24 03:34:56 CEST 2013


On 05/23/2013 03:57 PM, Citizen Kant wrote:

It's quite hard to believe that you're not just trolling.  Little that 
you say below makes any sense with regards to Python.


> I guess I'm understanding that, in Python, if something belongs to a type,
> must also be a value.
>

Nothing belongs to a type.  Objects created during the running of a 
program do have a definite type, and a definite value.  Some are 
immutable, meaning they cannot change.  Others are mutable. Examples are 
int and list, respectively.

> I guess I'm understanding that the reason why 9 is considered a value, is
> since it's a normal form*,* an element of the system that cannot be
> rewritten and reduced any further.

9 is a numeric literal in your source code that describes the integer 
nine.  Since it starts with a digit, and does not have quotes around it, 
it will be represented in the virtual machine as an integer object.

>
> I also guess I'm understanding that the same goes somehow for the letter A
> for example, since it cannot be rewritten or reduced any further, so it's a
> value too.
>

The letter A in your source code might be almost anything.  If it stands 
by itself, or is surrounded just by letters and digits, then it's a 
name, or identifier, presumably defined in some namespace.

That same A in the source code could be part of a string literal, if 
it's between quote marks.  The quote marks are not part of the string, 
they're merely part of the literal representation.  The language parser 
has to have some way of deciding whether you meant it as a name, or as a 
string.  The quotes define that.

> 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?

Letters and numbers can both be used inside a string literal.  What 
makes it a string literal is the presence of quote marks.

> Do I must
> observe this apostrophes thing like the symbol of the type itself inside
> which one can put any character, setting it as type str?
>

No clue what that's supposed to mean.

When the compiler processes your source file, it tokenizes it into some 
byte code.  When that byte code executes, objects are created, 
identifiers are bound and unbound to those objects, expressions are 
evaluated, functions are called, and possibly external devices are 
spoken to.

A string object has no quote marks around it (unless you go out of your 
way to add them to the string explicitly), and an int object has no 
definite format that is defined in the language.  They both have values, 
and sometimes its convenient to describe those values in the terms of 
source code.   But an int object for example is unlikely to be in base ten.

-- 
DaveA


More information about the Tutor mailing list