Adding String Numbers

Hi All :wave: :slightly_smiling_face:

Could anybody tell me why when adding two string numbers an output is actually given. What is happening under the hood? For example:

x = input( )
y = input( )
print( x + y )

I inputted 2 for x and 4 for y and the interpreter outputted 24.


What you are doing is concatenating two string objects. The fact that the objects happen to represent two numbers, is not relevant.

1 Like

Thank you. :slight_smile:

For others reading this post, a little more information:

print( “3” * 5 )

will output 33333

This is because “3” *5 is 5 times “3”, which is “33333”.

You are using strings, imagine like letters and words instead of math. You want to do 3*5 not “3”*5. So use int,(x) and int(y) or floats to process your input.