+ 1

Is there a practical usage in this? I dont get the example as, if its for the sum pourpose, why INT print(int("2") + int("3"))

still learning, so... maybe stupid question

3rd Oct 2018, 12:39 PM
Cristina Paixão
Cristina Paixão - avatar
4 ответов
+ 2
because if you don't specify, it will return strings by default and concatenate them and your result will be 23 instead of 5
3rd Oct 2018, 12:45 PM
Janning⭐
Janning⭐ - avatar
+ 2
you have to convert the strings to INT to get the value of the addition of the strings as INT. in this example, sum would be 5 of type INT. if you dont convert the strings, print("2" + "3") would print the concatenation of these strings, which is "23".
3rd Oct 2018, 12:46 PM
Kevin Dietrichstein
Kevin Dietrichstein - avatar
+ 2
Its useful when you have to add two integer stored like strings because + operator is defined for either (string and int) but with string you concatene they, while with int you add like in math. Example, assume that you have obtained from somewhere two integer from input BUT they are strings: a= "2" b= "3 and you want add they but like numbers, if you do print(a+b) you will get 23 because you are concatening two strings, while if you do print(int(a)+int(b)) you will get 5 because you effectively adding two ints (thanks to int function)
3rd Oct 2018, 12:49 PM
KrOW
KrOW - avatar
+ 2
thank you all, very quick 🙂 I get it
3rd Oct 2018, 1:01 PM
Cristina Paixão
Cristina Paixão - avatar