In Go language, fmt package implements formatted I/O with functions analogous to C’s printf() and scanf() function. The fmt.Printf() function in Go language formats according to a format specifier and writes to standard output. 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 Printf(format string, a ...interface{}) (n int, err error)
Parameters: This function accepts two parameters which are illustrated below:
- format string: This contains some strings along with some verbs.
- a …interface{}: This contains specified constant variables.
Return Value: It returns the number of bytes written and any write error encountered.
Example 1:
// Golang program to illustrate the usage of // fmt.Printf() function // Including the main package package main // Importing fmt import ( "fmt") // Calling main func main() { // Declaring some const variables const name, dept = "GeeksforGeeks", "CS" // Calling Printf() function fmt.Printf("%s is a %s Portal.\n", name, dept) // It is conventional not to worry about any // error returned by Printf. } |
Output:
GeeksforGeeks is a CS portal.
Example 2:
// Golang program to illustrate the usage of // fmt.Printf() function // Including the main package package main // Importing fmt import ( "fmt") // Calling main func main() { // Declaring some const variables const num1, num2, num3 = 5, 10, 15 // Calling Printf() function fmt.Printf("%d + %d = %d\n", num1, num2, num3) // It is conventional not to worry about any // error returned by Printf. } |
Output:
5 + 10 = 15
Recommended Posts:
- math.Lgamma() Function in Golang with Examples
- math.Float64bits() Function in Golang With Examples
- atomic.AddInt64() Function in Golang With Examples
- atomic.StoreInt64() Function in Golang With Examples
- reflect.FieldByIndex() Function in Golang with Examples
- string.Contains Function in Golang with Examples
- bits.Sub() Function in Golang with Examples
- io.PipeWriter.CloseWithError() Function in Golang with Examples
- time.Round() Function in Golang With Examples
- reflect.AppendSlice() Function in Golang with Examples
- reflect.ChanOf() Function in Golang with Examples
- flag.Bool() Function in Golang With Examples
- time.Sleep() Function in Golang With Examples
- time.Time.Year() Function in Golang with Examples
- reflect.DeepEqual() Function in Golang with Examples
- reflect.Indirect() Function in Golang with Examples
- reflect.CanAddr() Function in Golang with Examples
- reflect.CanInterface() Function in Golang with Examples
- reflect.CanSet() Function in Golang with Examples
- reflect.Cap() Function in Golang with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

