candycanearter07 <[email protected]>
writes:
> Lawrence D’Oliveiro <[email protected]> wrote at 02:05 this Sunday (GMT):
>> On 13 Dec 2025 11:55:35 GMT, Stéphane CARPENTIER wrote:
>>> Everything else is just a lot of lies. They pretend it's not
>>> strongly typed, but in the real world you will only encounter a lot
>>> of issue if you believe that.
>>
>> Think about why both JavaScript and PHP need a “===” operator, while
>> Python does not.
>>
>> It’s because Python is strongly typed.
>
> I thought it was because JS was too liberal with type-casting to make
> things true, and the JS devs didn't want to break compatibility.
“No implicit type conversion” is one of the definitions of strong
typing, at least back to the 1970s[1]. And JavaScript is certainly
weakly typed in that sense:
> 'a' + 1
'a1'
> 1/false
Infinity
What dividing by a boolean could possibly mean is a mystery, but
JavaScript will do it anyway.
Python fits this definition of strong typing up to a point:
>>> 'a' + 1
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
'a' + 1
~~~~^~~
TypeError: can only concatenate str (not "int") to str
However it only goes so far, for example many things will implicitly
convert to bool:
>>> not ''
True
>>> not {}
True
When you define your own classes, you can arrange for them to perform
arithmetic with other types without explicit conversions too.
Another property suggested in [1] for ‘strong typing’ is that functions
can only be called with with arguments matching a declared type. In
Python, function arguments do not have declared types[2] and does not
even infer them; anything goes. You will only hit an exception if you
try to use the arguments in the wrong way.
>>> def f(a,b):
... return a + b
...
>>> f("a", "a")
'aa'
>>> f(0,0)
0
>>> f("a", 0)
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
f("a", 0)
~^^^^^^^^
File "<python-input-0>", line 2, in f
return a + b
~~^~~
TypeError: can only concatenate str (not "int") to str
[1] https://dl.acm.org/doi/epdf/10.1145/942572.807045
[2] you can put in type annotations but the language implementation
ignores them - you need to run a separate static checker.
I would say that although Python does have some aspects of strong
typing, it is mostly weakly typed.
--
https://www.greenend.org.uk/rjk/
--
https://mail.python.org/mailman3//lists/python-list.python.org