Python how to remove last comma from print(string, end=“, ”)

前端 未结 5 1502
感动是毒
感动是毒 2021-01-13 05:40

my output from a forloop is

string = \"\"
for x in something:
   #some operation
   string =  x += string 

print(string)

5
66
777

I use

5条回答
  •  悲哀的现实
    2021-01-13 06:27

    list_1 = [5, 10, 15, 20]

    new_list = []
    [ new_list.append(f'({i}*{i+5})') for i in list_1 ] 
    print(*new_list,sep="+") 
    

    Output

    (5*10)+(10*15)+(15*20)+(20*25)
    

提交回复
热议问题