+ 1

Im confused if ('8' + 7) would be 87 or 15.

I'm confused every time I get a problem like that with a string number being added with an integer. Like would i add 8 and 7 or would i put those numbers together giving me 87

4th Mar 2017, 9:21 PM
Lulazy
Lulazy - avatar
6 Réponses
+ 10
If you a add two strings, you'll be concatenating them e.g: "8"+"7" = "87" If you add two integers: 8 + 7 = 15 If you try to "add" a string and a integer you'll receive an error message PS: I'm considering Python 3
4th Mar 2017, 10:56 PM
LayB
LayB - avatar
+ 1
its an error... string cnt be added to an integer... it cn only be added to a string
5th Mar 2017, 2:39 PM
Man-meet singh
Man-meet singh - avatar
+ 1
it will throw type error
11th Mar 2017, 4:49 PM
Rahul Pal
Rahul Pal - avatar
0
I have never seen languages where addition of string and number returns number as result. So just remember it and don't be confused next time 😉 In your case compiler automatically casts number (7) to string, so it works like '8' + '7' giving you string value '87'
4th Mar 2017, 10:07 PM
Ivan G
Ivan G - avatar
0
when you using a string value output is 87 .
4th Mar 2017, 10:18 PM
hosein shurabi
hosein shurabi - avatar
0
oooh okay
5th Mar 2017, 7:09 AM
Lulazy
Lulazy - avatar