New course! Every coder should learn Generative AI!
Try a free lesson+ 6
int("3" + "4") isn't necessarily the same as int("3") + int("4"), but rather the same as the following code (but without the extra variable):
x = "3" + "4" # x is now "34"
int(x) # Converts x to a string
With the int function, it will essentially evaluate the expression within the brackets before continuing with the type-conversion, which is why the output is 34 rather than 7
+ 2
Because the plus operator has three implementation. Arithmetic addition for integer, arithmetic addition for floating number and concantention for string.
When 3 is enclosed with quotation mark, it is a string, so the plus operator is string concantention here, just like "a" + "b" = "c"
+ 2
Int("3" +"4") will never be equal to 7. Because 3 and 4 are enclosed in a quote, which makes them a type string.
Int (3+4) != int("3" + "4").
The +sign just join the two strings together.
Like x = ( "james" + "bond" )
So, x = jamesbond
+ 1
In short,
You are using quotations so you're not adding, you're putting together.
If:
"A"+"b"= Ab
Then
"3"+"4"+= 34
0
Because ("3" + "4")-strings
But (3 + 4)-not strings