learnpython.org - an online interactive Python tutorial

Mel mwilson at the-wire.com
Fri Apr 22 15:07:17 CEST 2011

harrismh777 wrote:

> Heiko Wundram wrote:
>> The difference between strong typing and weak typing is best described
>> by:
>> Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
>> [GCC 4.3.4 20090804 (release) 1] on cygwin
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> >>>  1+'2'
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in<module>
>> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>>> >>>
> Yes. And you have managed to point out a serious flaw in the overall
> logic and consistency of Python, IMHO.
> Strings should auto-type-promote to numbers if appropriate.

"Appropriate" is the problem.  This is why Perl needs two completely 
different kinds of comparison -- one that works as though its operands are 
numbers, and one that works as though they're strings.  Surprises to the 
programmer who picks the wrong one.


More information about the Python-list mailing list