+ 1
"7" + 1 should be 71 Why Python occur an exception?
7 odpowiedzi
+ 2
you can't add two operands with different types
+ 1
Plus sign joins strings but in this case the number 1 is an integer.
You should do "7" + str(1) to get '71'
+ 1
you are trying to add numbers with string. it does not work in python , if trying to multiply string to an integer, oh yes , all right
+ 1
"7" is string and 1 is number. so it can't be added by + operands.
+ 1
Python won't implicitly coerce types on must cases, string addition is one of those.
+ 1
if you want to add string and integer you can use: str(value)+ int_value.
0
Thanks for good answers. In many other languages like JavaScript you can and string to number implicitly.