fmt.Sprintf() Function in Golang With Examples Last Updated : 05 May, 2020 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.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 need to import the "fmt" package in order to use these functions. Syntax: func Sprintf(format string, a ...interface{}) string Parameters: This function accepts two parameters which are illustrated below: format string: This includes some varbs along with some strings. a ...interface{}: This is the specified constant variables. Returns: It returns the resulting string. Example 1: C // Golang program to illustrate the usage of // fmt.Sprintf() function // Including the main package package main // Importing fmt, io and os import ( "fmt" "io" "os" ) // Calling main func main() { // Declaring some const variables const name, dept = "GeeksforGeeks", "CS" // Calling Sprintf() function s := fmt.Sprintf("%s is a %s Portal.\n", name, dept) // Calling WriteString() function to write the // contents of the string "s" to "os.Stdout" io.WriteString(os.Stdout, s) } Output: GeeksforGeeks is a CS Portal. Example 2: C // Golang program to illustrate the usage of // fmt.Sprintf() function // Including the main package package main // Importing fmt, io and os import ( "fmt" "io" "os" ) // Calling main func main() { // Declaring some const variables const num1, num2, num3 = 5, 10, 15 // Calling Sprintf() function s := fmt.Sprintf("%d + %d = %d", num1, num2, num3) // Calling WriteString() function to write the // contents of the string "s" to "os.Stdout" io.WriteString(os.Stdout, s) } Output: 5 + 10 = 15 Comment More infoAdvertise with us Next Article fmt.Sprintf() Function in Golang With Examples K Kanchan_Ray Follow Improve Article Tags : Go Language Golang-fmt Similar Reads 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.Printf() 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.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 3 min read 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.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 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 Like