2

I am currently looking for a way in which I can add a underscore in a string generated as such:

>>> bin(1)[2:].zfill(8) '00000001' 

I want the string to be '0_0_0_0_0_0_0_1'

How do i add the underscore between each character?

1
  • 1
    What about '_'.join(txt)? Commented Jul 13, 2017 at 7:43

1 Answer 1

2

This can be achieved in multiple ways and has already been answered a lot of times here. Usually people seem to do to some kind of replace operation but there are other ways. Here's how to use the String join() method.

s = "00000001" "_".join(s) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help though :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.