Println()
is defined in the fmt
package in Golang.
The following is the function prototype:
func Println(a ...interface{}) (n int, err error)
We use Println()
to write the input data stream to the standard output.
It is a variadic function, which means that it takes a variable number of input arguments.
The functionality of Println()
in Golang is similar to print
in python or printf
in C.
Note: The
Println()
function appends a new line at the end of the input data stream. Each of the input arguments will automatically be separated by a space in the output.
Println()
is a variadic function. Each input argument type is an empty interface
. This means we can pass any data type to the function ranging from (but not limited to) string
, float
, int
, or struct
.
The function takes the following input parameter:
a
: generic reference to input argument(s). The type of the input argument(s) is an empty interface
to accommodate all data types.The function returns the total number of characters written to the standard output, or an error if we are dealt one.
The function returns the following:
n
: int
value to represent the total number of characters written to the standard output.
err
: variable of type error
in case we are dealt with an error during execution of the function.
package mainimport "fmt"func main() {fmt.Println("Hello", "world!")name := "Bob"height := 156fmt.Println("Name:", name)fmt.Println("Height:", height, "cm")}
Free Resources