+ 1

Integers and Strings

If I type print(int("5" + "5")) it become 55 and not 10 ? I thought putting int first will make it into an int

12th Apr 2020, 5:53 AM
M.O.HONOR
M.O.HONOR - avatar
5 Réponses
+ 6
It witll return 55 because it runs first the codes in the bracket. If you want it to return 10 you should run the code like this print(int("5")+int("5")) this will allow to first transform the strings into integers and then sum the integers.
12th Apr 2020, 6:02 AM
João Cláudio Macosso
João Cláudio Macosso - avatar
+ 3
Inside items are taken as string not as integers because of ("" ) marks
12th Apr 2020, 5:55 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
If it will be int( 5 + 5 ) this will result in 10
12th Apr 2020, 5:55 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 2
First it will evaluate what is inside the brackets so "5"+"5" becomes 55 as it is a string then I will convert 55 to integer
13th Apr 2020, 11:13 AM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
0
Alright thx
12th Apr 2020, 11:57 AM
M.O.HONOR
M.O.HONOR - avatar