+ 2
What is the difference between >>>int('2')+int('3') and >>>2+3.
Both gives 5 only.
6 ответов
+ 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.
+ 3
you are correct, but just put 2.1 & 3.5 such as floats, you will see the difference
+ 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.
+ 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
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
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')