dynamic type variable

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Jan 20 21:58:45 EST 2008


En Mon, 21 Jan 2008 00:37:36 -0200, J. Peng <jpeng at block.duxieweb.com>  
escribi�:

> Python's variable is dynamic type,is it?

No. Python has objects, and names that refer to those objects. Objects  
have a type, which can't change once the object is created. But a name may  
refer to different objects of different types at different times.

See http://effbot.org/zone/python-objects.htm

> But why this can't work?
>
>>>> 3 + 'a'
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
>
> So I see the number 3 can't be converted to string type automacially.

Python never "converts" anything, except numeric types in expressions  
(2+3.0, sqrt(5L)) and sometimes string/unicode.

-- 
Gabriel Genellina




More information about the Python-list mailing list