On Tue, Apr 7, 2020 at 2:42 AM Christopher Barker <python...@gmail.com> wrote:
> This all made me think *why* do I type check strings, and virtually nothing 
> else? And it's because in most otehr places, if I want a given type, I can 
> just try to make it from teh input:
>
> x = float(x)
> i = int(i)
>
> arr = np.asarray(np)
>
> but:
>
> st = str(st)
>
> doesn't work because ANY object can be made into a string.
>

Not sure I understand your point here. Calling float() or int() will
give you a float or int for many values that aren't floats or ints,
just as calling str() will give you a string. The only real difference
(as far as I can tell) is that, as you say, any object can be
stringified. But all of those operations are potentially lossy -
int(1.5) and float(1e100000) both throw away information - and they
don't prove that something already was a string/int/float, just that
it _now_ is. And to that end, str is no worse than the others.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BHPETN7GRBZSYDOEY6DS2BDHVKIR2AGO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to