This question already has an answer here:
I am trying to understand this example from the Go Tour.
What is the significance of this last comma on line 3
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20),
)
How do line breaks generally modify the code in go.
I know, that without the line breaks, I can write this statement as
fmt.Println( pow(3, 2, 10), pow(3, 3, 20) )
and it would compile.
So, why is the extra comma needed with line breaks
</div>
Go "automatically" adds ;
as the end of a statement.
So
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20),
)
as the same as
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20),
);
But
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20)
)
is the same as
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20);
);
which is obvioulsy a syntax error.
There's no significance. Trailing commas are allowed in function calls, although go fmt
will remove them.