Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

I want to change a tuple into string without joining it in python. How could I do that?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  t = ('a', 'b', 'c')
  s = 'a','b', 'c'
  print(s==t)
  # output True

if you want s = 'a,b,c' then you can do it by joining which you do not want to do. Also, it's useless to write 'a','b','c' as string, however you can do that by using commented code. Please consider writing s = a,b,c

s = ''
for i in t:
    s += str(',') + i          # s += str(',') + str("'") + i + str("'")
s = s[1:]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...