Re: Cannot Convert input into integer
Wildemar Wildenburger wrote:
Arne VajhQj wrote:
Silfax wrote:
"14" * 3 == 42
as does rexx also
python returns a more sensible 141414 in this case.
I am not sure everyone agrees on that being "sensible" ...
Right, but they should! ;)
(Note that the 141414 should be "141414" there.)
Because, well, when I read
"14" * 3
it looks to me like someone wants the string "14" three times. OK, one
could argue that a list or tuple of three individual "14"-strings is
even more sensible, but I can not see much use for that.
Probably just my yearlong exposure to python as my first real language
speaking, of course ;).
The curse of dynamic typing meets the geas of the overloaded operator.
There is no cross-language standard for the meaning of "*" where the operands
are strings. There is no cross-language standard for which operator gets
promoted when a binary operation involves both an int and a string.
One of the reasons that Java is strongly typed is to make such things
(painfully) explicit.
Each language gets to decide about these things. Java leaves it up to the
individual method, such as PrintStream.println(), to decide how to interpret
its arguments, and inbuilds just a little mechanism into Object, such as
toString(), to help things along.
--
Lew