Hacker News new | past | comments | ask | show | jobs | submit login

Here is the most common definition of strong typing, and below it an assertion that "Smalltalk, Perl, Ruby, Python, and Self are all strongly typed".

https://en.wikipedia.org/wiki/Strong_and_weak_typing#Implici...




That is quite a disingenuous quote... the actual content is:

> Smalltalk, Perl, Ruby, Python, and Self are all "strongly typed" in the sense that typing errors are prevented at runtime and they do little implicit type conversion, but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules. The term duck typing is now used to describe the dynamic typing paradigm used by the languages in this group.

That is quite a qualified usage.

The only feature distinguishing Python from Javascript here is that Python does less implicit type conversion (where it is reasonable v.s. where it is insane). In every other dimension it is the same.


Do you have an example of Python doing implicit type conversion?


Python2 implicitly converts int to long and str to unicode:

    >>> 2**100
    1267650600228229401496703205376L
    >>> 'x' + u'y'
    u'xy'
All Pythons implicitly convert int to float and int or float to complex:

    >>> 1 + .5
    1.5
    >>> 2 * 3j
    6j
Methods like list.extend now, in recent versions of Python (since 2.1), accept arbitrary iterables rather than just lists; it's more debatable whether this is an “implicit type conversion” or not.

    >>> x = [3, 4]; x.extend((5, 6)); x
    [3, 4, 5, 6]


Thanks for the examples. I was mainly thinking of int-float conversion that is present in the vast majority of languages.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: