In just learning python in encountered a problem that the output string of numbers, separated by semicolons, but do not need the last comma,
At this point how to do it?
print (i, end = ',') in this way there will be a final extra comma
As a white, I found two ways, of course, with the back of the in-depth study, there may be many ways with, here only to record their
The study, to facilitate later review:
1. Add the contents back to define an empty string, then will input comma, and connected, the final output:
s = ''
for i in range(100, 110):
s += '{},'.format(i)
print(s[:-1])
2. definition list, then the contents of the list to be output is stored, is connected to the last comma:
s = []
for i in range(100, 110):
s.append(str(i))
print(','.join(s))
Note: i use str converted into characters