+ 1

Understanding y = int(str(y)

x = 5 y = x + 3 y = int(str(y) + "2") I know the answer is 82. But I get the same answer if I remove the int() and just use str(). Example: y = str(y) + "2") Why does the code use this?

20th Aug 2020, 8:18 PM
Michael King
Michael King - avatar
2 Respuestas
+ 6
Try running this to help understand x = 5 y = x + 3 y = int(str(y) + "2") print(y,'is',type(y)) z = str(y) + '2' print(y,'is',type(z))
20th Aug 2020, 8:36 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
In python strings are printed to the console without quotes that's why it looks identical. You should check documentation about type conversion and base types for better understanding
20th Aug 2020, 8:38 PM
Kate
Kate - avatar