Home > Net >  Is there a way to change space size between chars in a string?
Is there a way to change space size between chars in a string?

Time:09-07

let's say I have this string:

my_string='hello'

Is there a way to change the spacing between each charcter in the original string? What I mean in spacing is like:

new_string='h e l l o'

I want to create customzied space,not space like this:('one space' key)

' '

Basically,change 'one space' to my own defintion of 'one space',not necessary using space key.(What I mean in not necessary using space key is not using it like that:(three 'one space' key))

'   '

CodePudding user response:

my_string = "Hello"
print(" ".join(my_string))

CodePudding user response:

to get it a bit more flexible according the number of spaces, we can use this:

my_string='hello'
count = 1
print((" " * count).join(my_string))
  • Related