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.

Thanks,
Tom

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

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.