Pass sep=","as an argumentprint()
You are almost there with an expression for print.
There is no need for a loop, print has a parameter sepas well end.
>>> print(*range(5), sep=", ")
0, 1, 2, 3, 4
Little explanation
print . , sep. sep .
>>> print("hello", "world")
hello world
sep .
>>> print("hello", "world", sep=" cruel ")
hello cruel world
, str(). print , .
>>> print(["hello", "world"], sep=" cruel ")
['hello', 'world']
, , sep.
>>> print(*["hello", "world"], sep=" cruel ")
hello cruel world
>>> print(*range(5), sep="---")
0---1---2---3---4
join
join .
>>>print(" cruel ".join(["hello", "world"]))
hello cruel world
, .
>>>print(",".join([str(i) for i in range(5)]))
0,1,2,3,4
-
, , , , . , , .
>>>iterable = range(5)
>>>result = ""
>>>for item, i in enumerate(iterable):
>>> result = result + str(item)
>>> if i > len(iterable) - 1:
>>> result = result + ","
>>>print(result)
0,1,2,3,4