take – Why does Lua "print" print extra spaces in arguments?

Question:

I used the print() command concatenating a variable, but the output prints extra spaces. If I use io.write() , this problem doesn't occur. Why does this problem happen with print() ?

Example:

name = "Peter"

print("The length of the name is: ", #name)

Expected result: The length of the name is: 5

Result obtained: The length of the name is: 5

Answer:

The print function in lua adds a tab between each argument, code describing this is available on github:

https://github.com/lua/lua/blob/681297187ec45268e872b26753c441586c12bdd8/lbaselib.c#L31

To gain more control over the output, use io.write

Scroll to Top