Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197646
| From | Richard Kettlewell <invalid@invalid.invalid> |
|---|---|
| Newsgroups | comp.os.linux.misc, alt.folklore.computers, comp.lang.python |
| Subject | Re: Python (was Re: Recent history of vi) |
| Date | 2025-12-20 10:12 +0000 |
| Organization | terraraq NNTP server |
| Message-ID | <wwvzf7djwbi.fsf@LkoBDZeT.terraraq.uk> (permalink) |
| References | (16 earlier) <10ghqrq$g7pg$1@dont-email.me> <wwvy0nma8fp.fsf@LkoBDZeT.terraraq.uk> <693d5437$0$2499$426a34cc@news.free.fr> <10hl622$jeli$11@dont-email.me> <slrn10kakjl.14g1t.candycanearter07@candydeb.host.invalid> |
Cross-posted to 3 groups.
candycanearter07 <candycanearter07@candycanearter07.nomail.afraid>
writes:
> Lawrence D’Oliveiro <ldo@nz.invalid> 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/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Python (was Re: Recent history of vi) Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-14 02:05 +0000
Re: Python (was Re: Recent history of vi) candycanearter07 <candycanearter07@candycanearter07.nomail.afraid> - 2025-12-19 13:30 +0000
Re: Python (was Re: Recent history of vi) Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-19 20:58 +0000
Re: Python (was Re: Recent history of vi) rbowman <bowman@montana.com> - 2025-12-20 05:48 +0000
Re: Python (was Re: Recent history of vi) Richard Kettlewell <invalid@invalid.invalid> - 2025-12-20 10:12 +0000
Re: Python (was Re: Recent history of vi) c186282 <c186282@nnada.net> - 2025-12-20 05:25 -0500
Re: Python (was Re: Recent history of vi) rbowman <bowman@montana.com> - 2025-12-21 04:22 +0000
Re: Python (was Re: Recent history of vi) Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-20 22:28 +0000
Re: Python (was Re: Recent history of vi) rbowman <bowman@montana.com> - 2025-12-21 04:25 +0000
csiph-web