What is the difference between >>>int('2')+int('3') and >>>2+3. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between >>>int('2')+int('3') and >>>2+3.

Both gives 5 only.

5th Aug 2016, 3:25 PM
Raj shah
Raj shah - avatar
6 Answers
+ 6
Sometimes the summary is the same. But its only the output of the interpreter. So IN the machine it looks much complicated. So you have to try more difficult and complicated code, like the dude before me wrote.
5th Aug 2016, 4:09 PM
Andreas Kilian
Andreas Kilian - avatar
+ 3
you are correct, but just put 2.1 & 3.5 such as floats, you will see the difference
5th Aug 2016, 4:01 PM
Ayesh Weerasinghe
Ayesh Weerasinghe - avatar
+ 1
when using not the containment inside the quotes will produce what's inside the quotes combined total, no matter what the set number is, but the fixed figures simply added 2+3 will always and only equal 5 versus if you change the the int to fluctuating variables.
5th Aug 2016, 8:46 PM
lateefasmith
+ 1
>>>int('2')+int('3') '2' means a string. int ('2') means a string converted to integer. string 2 converted to integer + string 3 converted to integer so, now it becomes 2+3 so, output will be 5 see this example. int ('2' + '3') gives the output as 23 Because, two strings '2' and '3' are in parenthesis and added. it becomes '23' which is a string. now, '23' which is a string converted to integer when parenthesis removed. so, final output will be 23. and >>>2+3 are pure integers so output will be 5
5th Sep 2016, 6:54 PM
Veluri Reddy
Veluri Reddy - avatar
0
I tried print(2.1+3.5) and it added the floats perfectly but when I tried int ('2.1')+int('3.5') it did not compute. what's the point of using this method compared to simply adding the floats
12th Aug 2016, 9:12 PM
Corlene 'Corey' Greenwood
Corlene 'Corey' Greenwood - avatar
0
2.1+3.5 are addition in floats. Python automatically assigns type floats to the number which have a decimal. int ('2.1')+int('3.5')....this gives error. '2.1' is a string which has a decimal. Python does not recognise a number having a decimal as integer. so, you can convert it into a float but not integer. so, try this float ('2.1')+float('3.5')
5th Sep 2016, 7:04 PM
Veluri Reddy
Veluri Reddy - avatar