I have a simple code below which adds the sum of 2 numbers together. However, I don't understand why the comma is able to print the result with a string datatype together with a float datatype. Does anyone know the explanation behind this concept of being able to add the string and float datatype together without conversion of the result variable?
Because, if the addition operator was to be used, I would have to convert the result variable from a float datatype to a string so that I can print the result with no errors. Thank you.
The code that adds the string and float datatypes together using ,
:
firstnum = float(input("Enter the first number: "))
secnum = float(input("Enter the second number: "))
result = firstnum + secnum
print ("The sum of the two numbers is: ", result)
VS
The code that adds the string and float datatype using +
:
firstnum = float(input("Enter the first number: "))
secnum = float(input("Enter the second number: "))
result = firstnum + secnum
convertedstring = str(result)
print ("The sum of the two numbers is: " + convertedstring)'''