+ 2

Why is there a space in the output without adding the space myself?

Hi all, Can someone explain why the following code... ages = {"Tonja":45, "John":46} print("John is",ages["John"]) print("Tonja is",ages["Tonja"]) Gives the following result... John is 46 Tonja is 45 I write the following code: print("John is"..., instead of print("John is "..., so I expect no space between "is" and the age. Why is there a space anyway in the output? Thanks in advance

12th Nov 2016, 7:55 PM
John Been
John Been - avatar
4 ответов
+ 3
Use print("text1", "text2", sep = x, end = y) to control the separating string, where x separates text1 and text2, where y is printed after printing all the text parameters. x is ' ' by default. y is '\n' by default.
13th Nov 2016, 4:16 AM
Samuel Neo
Samuel Neo - avatar
+ 2
I think it does that automatically, since if the number were negative, then that space would be taken up by the negative sign.
12th Nov 2016, 7:59 PM
Keto Z
Keto Z - avatar
+ 2
As far as I know, it is because of the "coma", just change it for a "plus" sign
30th Nov 2016, 12:23 AM
Iván Baca
Iván Baca - avatar
0
Hi Samuel and Keto. Thank you both for your replies.
16th Nov 2016, 3:50 PM
John Been
John Been - avatar