Weak Type Ability for Python
Thomas Passin
list1 at tompassin.net
Thu Apr 13 08:10:30 EDT 2023
On 4/13/2023 1:38 AM, avi.e.gross at gmail.com wrote:
> In Python, "+" does not
> mean plus at all. It means whatever the programmer wanted it to mean. An
> infix line of code that includes "obj1 + obj2" is supposed to investigate
> how to do it. I am not sure if some built-in objects may be different, but
> it does a sequence of operations till it finds what it needs and does it.
A really nice example of this is pathlib in the standard library. You
can write things like this, overloading the "/" operator:
>>> from pathlib import PurePath
>>> pth = PurePath('c:/') / 'temp' / 'python'
>>> pth
PureWindowsPath('c:/temp/python')
>>> str(pth)
'c:\\temp\\python'
More information about the Python-list
mailing list