+ 2

why has to be int("2")+int("3"), not just 2+3

6th Feb 2017, 8:04 AM
Olyvia
Olyvia - avatar
4 Respostas
+ 23
"2" and "3" are strings - if you add them (concatenate) together, you will get "23" - which will still be a string. If you want to add 2 + 3, simply add 2+3 :) If you have strings like above and still want to add them like numbers, you have to tell Python that you want to treat them like numbers - that's what int() is for - it converts string to numbers (if the string contains digits exclusively).
6th Feb 2017, 8:11 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 15
print("2" + "3") # outputs 23 print(int("2") + int("3")) # outputs 5 print(2 + 3) # outputs 5
6th Feb 2017, 8:10 AM
Hatsy Rei
Hatsy Rei - avatar
+ 11
a=2+3 print(a) # it can be 2+3
6th Feb 2017, 9:35 AM
Ahri Fox
Ahri Fox - avatar
+ 8
@hosein it can't print a I think you meant sum copier ;)
6th Feb 2017, 12:46 PM
Ahri Fox
Ahri Fox - avatar