Adding a comma to a string

Asked

Viewed 995 times

5

Good personal and possible to add comma in an example string:

a = '1234567890abcdefghijklmnopqrstuvwxyz_'

for her to stay like this a = 1,2,3,4,5,6,7....

1 answer

5


Do the following:

lst = list(a) // transforma sua string em lista 
txt = ",".join(lst) // coloca vírgula entre as letras

Note that this can be done in just one step:

a = ",".join(a)
  • Thank you Eduardo for that.

  • 1

    You’re welcome :) @Glauciofonseca

  • 1

    You can also be more direct right using: >>> a = "1234567890abcdefghijklmnopqrstuvwxyz_" >> a = ",". join(a)
>>> a
'1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,_'

  • 1

    Why not a = ",".join("1234567890abcdefghijklmnopqrstuvwxyz_")?... Relax, it’s just to relax.

  • 1

    hahahahahahahahahahah... Ufa :)

  • hahahahaha and this :)

  • Actually I use the python console a lot to keep doing these crazy my kkkkk

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.