fmt.Sprintln returns a String, but doesn't print anything. (The name was taken from the also confusingly named C function sprintf.)

What you need is Printf, but you have to add the newline yourself:

fmt.Printf("inc 1 equal %v\n", inc(1))
Answer from Thomas on Stack Overflow
🌐
Reddit
reddit.com › r/golang › easier string interpolation
r/golang on Reddit: Easier String interpolation
July 19, 2023 -

Does anyone know of an easier way to interpolate strings?

This works:

cheese := "gouda"

fmt.Printf("I like %s", cheese)

But it would so much nicer if there is a way to put the variables in the string like many other languages. For a single variable, it's not so bad, but when you have a bunch, it isn't very efficient.
Eg. Python:
chesse = "gouda"
print(f"I like {cheese}")

or Dart:
String cheese = "gouda"
print("I like $cheese");

Discussions

proposal: Go 2: string interpolation
I used to think it was a gimmick but it is not in fact. It is actually a way to provide type safety for string formatting. I mean compiler can expand interpolated strings into expressions and perform all kind of type checking needed. More on github.com
🌐 github.com
112
September 8, 2019
How to interpolate multiline string?
Hi guys, I have not found examples so far about this: is it possible to return an interpolated string with the variables’ actual values? supposing we have a multiline string like so: placeHoldersString := `Your name: %s \n Your city: %s Your country: %s` Can I use filledString := ... More on forum.golangbridge.org
🌐 forum.golangbridge.org
1
0
February 17, 2021
C# syntax (Interpolated Strings?)
One thing that I really liked in C# was the way you could write: int age = 80; string s = $"I am {age} years old."; Is there a package for Go that can do something similar? Does fmt support a similar syntax? I am of course aware of the syntax below, but it is a little bit longer and not as ... More on forum.golangbridge.org
🌐 forum.golangbridge.org
0
2
September 10, 2020
proposal: Go 2: string interpolation evaluating to string and list of expressions
What other languages do you have experience with? Java, C#, Kotlin, JavaScript · Has this idea, or one like it, been proposed before? proposal: Go 2: string interpolation #34174 proposes string interpolation similar to other languages like C# and Kolin. More on github.com
🌐 github.com
38
January 11, 2022

fmt.Sprintln returns a String, but doesn't print anything. (The name was taken from the also confusingly named C function sprintf.)

What you need is Printf, but you have to add the newline yourself:

fmt.Printf("inc 1 equal %v\n", inc(1))
Answer from Thomas on Stack Overflow
🌐
Bacancy Technology
bacancytechnology.com › qanda › golang › go-string-interpolation
Simplify String Format: A Guide to Go String Interpolation
April 16, 2024 - String interpolation, also known as string formatting, is a fundamental concept in programming languages that allows developers to embed variables or expressions within strings. In Go, string interpolation provides a convenient way to construct ...
🌐
Wikipedia
en.wikipedia.org › wiki › String_interpolation
String interpolation - Wikipedia
March 31, 2026 - String interpolation is common in many programming languages which make heavy use of string representations of data, such as Apache Groovy, Julia, Kotlin, Perl, PHP, Python, Ruby, Scala, Swift, Tcl and most Unix shells.
🌐
Medium
channaly.medium.com › string-interpolation-in-golang-ecb3bcb2d600
String interpolation in golang. You might have written many string… | by Ly Channa | Medium
January 20, 2020 - If you see the example from PHP ... of year, month and day, however in a static, compiled language like Go, we need to specify types of ......
🌐
Willem.dev
willem.dev › articles › string-interpolation
No string interpolation in Go/Golang. Use these alternatives
July 3, 2024 - This evaluation and replacement is called string interpolation. You’re essentially providing mini-templates in which you can directly refer to variables. As said before, Go does not support string interpolation.
Find elsewhere
🌐
Leapcell
leapcell.io › blog › string-interpolation-in-go-current-methods-and-community-discussions
String Interpolation in Go: Current Methods and Community Discussions | Leapcell
July 25, 2025 - Go does not natively support string interpolation, relying on fmt.Sprintf for formatting. A proposal for string interpolation was declined due to redundancy and language simplicity concerns.
🌐
Go Packages
pkg.go.dev › go.uber.org › yarpc › internal › interpolate
interpolate package - go.uber.org/yarpc/internal/interpolate - Go Packages
Parse parses a string for interpolation. Variables may be specified anywhere in the string in the format ${foo} or ${foo:default} where 'default' will be used if the variable foo was unset.
🌐
GitHub
github.com › golang › go › issues › 34174
proposal: Go 2: string interpolation · Issue #34174 · golang ...
September 8, 2019 - Introduction For ones who don't know what it is: Swift let multiplier = 3 let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)" // message is "3 times 2.5 is 7.5" Kotlin var age = 21 println("My Age Is: $age") C# string ...
Author   sirkon
🌐
Go Packages
pkg.go.dev › github.com › evandrojr › string-interpolation
string-interpolation command - github.com/evandrojr/string-interpolation - Go Packages
Interpolates anything in an easy way. No need to pass the format parameters %d, %s, %t... anymore! ... package main import ( "github.com/evandrojr/string-interpolation/esi" ) func main() { esi.Print("Print ", 10, " ", 7, " interpolates anything ", true, " ", 3.4e10) esi.Print(" no line break") esi.Println() esi.Println("Println ", 10, " ", 7, " interpolates anything ", true, " ", 3.4e10) f := esi.Sprint("Sprint ", 10, " ", 7, " interpolates anything ", true, " ", 3.4e10) esi.Print(f) }
🌐
GitHub
github.com › mfridman › interpolate
GitHub - mfridman/interpolate: A Go library that helps substitute variables in strings from environment variables · GitHub
A Go library for parameter expansion (like ${NAME} or $NAME) in strings from environment variables. An implementation of POSIX Parameter Expansion, plus some other basic operations that you'd expect in a shell scripting environment like bash.
Author   mfridman
🌐
GoLinuxCloud
golinuxcloud.com › home › golang string interpolation explained [with examples]
Golang string interpolation Explained [With Examples] | GoLinuxCloud
September 13, 2022 - String interpolation is the process of inserting data from a variable or expression into a placeholder within a string. It is an important feature because it enables us to provide our applications more readable and flexible instead of hard coding.
🌐
TutorialsPoint
tutorialspoint.com › go › go_string_interpolation.htm
Go - String Interpolation
The first example demonstrates use of sprintf and the second example shows how to use printf to execute string interpolation. In this method, the name and age variables' values are combined into a string using fmt.Sprintf() function which demonstrate interpolation.
🌐
The New Stack
thenewstack.io › home › an introduction to string formatting in go
An Introduction to String Formatting in Go - The New Stack
May 31, 2024 - Learn all about the simplicity ... formatting, otherwise known as string interpolation, is when you insert a custom string or variable into predefined text....
🌐
Go Forum
forum.golangbridge.org › getting help
C# syntax (Interpolated Strings?) - Getting Help - Go Forum
September 10, 2020 - One thing that I really liked in C# was the way you could write: int age = 80; string s = $"I am {age} years old."; Is there a package for Go that can do something similar? Does fmt support a similar syntax? I am of course aware of the syntax below, but it is a little bit longer and not as ...
🌐
GitHub
github.com › buildkite › interpolate
GitHub - buildkite/interpolate: Interpolate $STRINGS in ${OTHER_STRINGS:-true}
A golang library for parameter expansion (like ${BLAH} or $BLAH) in strings from environment variables. An implementation of POSIX Parameter Expansion, plus some other basic operations that you'd expect in a shell scripting environment like bash.
Starred by 35 users
Forked by 6 users
Languages   Go 97.0% | Shell 3.0% | Go 97.0% | Shell 3.0%
🌐
LabEx
labex.io › tutorials › go-how-to-print-string-interpolation-431379
How to print string interpolation | LabEx
The most common way to perform string interpolation in Golang is using the fmt.Sprintf() function. This function takes a format string and a list of values, and returns a new string with the values inserted into the format string.
🌐
GitHub
github.com › golang › go › issues › 50554
proposal: Go 2: string interpolation evaluating to string and list of expressions · Issue #50554 · golang/go
January 11, 2022 - What other languages do you have experience with? Java, C#, Kotlin, JavaScript · Has this idea, or one like it, been proposed before? proposal: Go 2: string interpolation #34174 proposes string interpolation similar to other languages like C# and Kolin.
Author   Cookie04DE
🌐
Medium
medium.com › rungo › string-formatting-in-go-dd752ff7f60
String formatting in Go. String formatting or String… | by Uday Hiwarale | RunGo | Medium
September 1, 2020 - GOLANG String formatting in Go String formatting or String interpolation is an important concept in any language. Printf would probably be the general implementation of how a variable of any type is …