Is there a way to use the sep="" function with an inputed string

606 Views Asked by At

I have been trying to use the separator function with a message that uses the input function, but it seems the that the separator function does not work and it only prints out the inputed phrase. For ex. I use sep="..." and would expect my inputed phrase to print out "This...Is...My...Inputed...Phrase" but instead I receive "This is my inputed phrase".

# Asking for user to input any phrase or word they want
user_phrase = input('What is the phrase you want to print?')

# using the seperator function to seperate the inputed phrase by the desired users choice of string.
print(user_phrase, sep='...')
1

There are 1 best solutions below

0
Mark On

The sep parameter is used when you pass in more than one argument to print() like:

print("some string", "some other string", sep="...")
# some string...some other string

To get your desired output, you need to turn your single string into multiple strings. split() will do that. Then you need to turn those into individual arguments to print(). You can do that like this:

s = "This is my inputed phrase"
print(*s.split(), sep='...')
# This...is...my...inputed...phrase