M.Zul M.Zul - 3 months ago 13
Swift Question

print ("Hello World") in swift showing as "Hello World\n"

I have just started out in swift and i have been practising it for awhile. But often when i am printing a statement such as "Hello World" in the playground, it shows it as "Hello World\n". I am not sure why. Please do help me out with this.
This is my very own question. I couldn't find answers and so I decided to ask out in the community.

Answer

The print function

print("Hello world")

does print the value it receives as param + a new line character \n.

"Hello world" + "\n" -> "Hello world\n"

If you don't want the \n at the end you can tell the print function to omit it

print("Hello world", terminator: "")