Given a list of floats:
my_list = [0.3, 0.11, -0.9]
I want a string literal object:
my_string = "0.3, 0.11, -0.9"
Attempt:
print(', '.join(inputs))
> TypeError: sequence item 0: expected str instance, float found
Try this:
print(' , '.join(str(x) for x in [0.3, 0.11, -0.9]))
you can use join function of string like this:
first you have to convert float to str
my_string = ', '.join([str(i) for i in my_list])
', '.join([float(i) for i in inputs]) but got TypeError: sequence item 0: expected str instance, float found.Arguably, the easiest way would be to do:
my_string = str(my_list)[1:-1]
This takes my_list, converts it into a string, and takes the characters from 1)leaving the first character at 0) to -1 (the end character is not taken)