Can i concatenate to different data type in 1 string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can i concatenate to different data type in 1 string

eg 268.4537 is float and "happy" is string I want out put as "268.4537 happy" how can I archive this

4th Apr 2018, 6:27 AM
Sandeep Talware
Sandeep Talware - avatar
4 Answers
+ 4
You only need to convert the data type with the str() function: my_num = 3.8 my_str = "Hello" print (my_str + str(my_num)) There are other ways to do what you like (format a string), here you have more information: http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-JUMP_LINK__&&__python__&&__JUMP_LINK
4th Apr 2018, 6:40 AM
Mickel
Mickel - avatar
+ 2
In what language?
4th Apr 2018, 6:34 AM
Mickel
Mickel - avatar
+ 1
thanks mickel
4th Apr 2018, 6:41 AM
Sandeep Talware
Sandeep Talware - avatar
4th Apr 2018, 6:34 AM
Sandeep Talware
Sandeep Talware - avatar