fmt.Printf() Function in Golang With Examples Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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. Conversion Characters: Conversion CharactersDescription%bIt is used to format base 2 numbers%oIt is used to format base 8 numbers%OIt is used to format base 8 numbers with 0o prefix%dIt is used to format base 10 numbers with lower-case letters for a-f%xIt is used to format base 16 numbers with upper-case letters for A-F%XIt is used to format base 16 numbers%gIt is used to format float values%sIt is used to format string values%tIt is used to format true or false values%eIt is used to format scientific values Example 1: Go // 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: Go // 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 Example 3: Go // Golang program to illustrate the usage of // fmt.Printf() function // Including the main package package main // Importing fmt import ( "fmt" ) // Calling main func main(){ var str = "Geeksforgeeks" fmt.Printf("The string is %s \n", str) var num1 int = 21 fmt.Printf("The decimal value is %d \n", num1) var num2 float32 = 7.786 fmt.Printf("The floating point is %g \n", num2) var num3 int = 14 fmt.Printf("The binary value of num3 is %b \n", num3) var num4 = 4 + 1i fmt.Printf("Scientific Notation of num4 : %e \n", num4) } Output: The string is Geeksforgeeks The decimal value is 21 The floating point is 7.786 The binary value of num3 is 1110 Scientific Notation of num4 : (4.000000e+00+1.000000e+00i) Comment More infoAdvertise with us Next Article fmt.Printf() Function in Golang With Examples K Kanchan_Ray Follow Improve Article Tags : Go Language Golang-fmt Similar Reads fmt.print() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.print() function in Go language formats using the default formats for its operands and writes to standard output. Here Spaces are added between operands when any string is not 2 min read fmt.Sprintf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprintf() function in Go language formats according to a format specifier and returns the resulting string. Moreover, this function is defined under the fmt package. Here, you 2 min read fmt.Sprint() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprint() function in Go language formats using the default formats for its operands and returns the resulting string. Here spaces are added between operands when any string is 3 min read fmt.Println() Function in Golang With Examples 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 2 min read fmt.Sprintln() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprintln() function in Go language formats using the default formats for its operands and returns the resulting string. Here spaces are always added between operands and a newl 2 min read Like