fmt.Sprintf() Function in Golang With Examples Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue 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: // 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: // 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 Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now! Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 05 May, 2020 Like Article Save Article Previous Compare Println vs Printf in Golang with Examples Next fmt.Sprintln() Function in Golang With Examples Share your thoughts in the comments Add Your Comment Please Login to comment...