0

I get same results via these two statement in python:

print("Hello", username) # I don't need to give space after Hello

print("Hello " + username) # I need to give space after Hello

What is the difference? If you could please share link/example for me to understand.

0

2 Answers 2

2
print(*items, sep=' ', end='\n', file=sys.stdout, flush=False)

As you can see, you can pass a value for the character that will separate all the strings you want to get printed out. Set sep='' if you don't want them to be separated by a space.

Sign up to request clarification or add additional context in comments.

Comments

1

In the first case, you are giving multiple inputs to the print() function. The print function will put a space between the inputs when it prints them.

In the second case you are combining two strings using the (+) operation. And the combined string is the input to the print() function. That is why you need to add the space, because in this case you are constucting your output string as one unit and then passing it to the print() function.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.