+ 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
6 odpowiedzi
+ 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
+ 1
its an error... string cnt be added to an integer... it cn only be added to a string
+ 1
it will throw type error
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'
0
when you using a string value output is 87 .
0
oooh okay