fmt.Println() Function in Golang With Examples
Last Updated :
05 May, 2020
In Go language, fmt package implements formatted I/O with functions analogous to C’s printf() and scanf() function. The fmt.Println() function in Go language formats using the default formats for its operands and writes to standard output. Here spaces are always added between operands and a newline is appended at the end. Moreover, this function is defined under the fmt package. Here, you need to import the “fmt” package in order to use these functions.
Syntax:
func Println(a ...interface{}) (n int, err error)
Here, “a …interface{}” contains some strings including specified constant variables.
Return Value: It returns the number of bytes written and any write error encountered.
Example 1:
package main
import (
"fmt"
)
func main() {
const name, dept = "GeeksforGeeks" , "CS"
fmt.Println(name, "is" , "a" , dept, "Portal." )
}
|
Output:
GeeksforGeeks is a CS Portal.
In the above code, it can be seen that the function Println() is not containing any space within the specified strings still in output is print space that can be seen from the above output.
Example 2:
package main
import (
"fmt"
)
func main() {
const num1, num2, num3, num4 = 5, 10, 15, 50
fmt.Println(num1, "+" , num2, "=" , num3)
fmt.Println(num1, "*" , num2, "=" , num4)
}
|
Output:
5 + 10 = 15
5 * 10 = 50
In the above code, it can be seen that the function Println() is not using any newline (\n) still in the output it prints new line that can be seen from above shown output.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...