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");

🌐
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 ... types of year, month and day, however in a static, compiled language like Go, we need to specify types of ......
Discussions

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
proposal: Go 2: string interpolation
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 = ... More on github.com
🌐 github.com
112
September 8, 2019
Named String Formatting
Hi Folks, I wanted to interpolate string and get the formatted output using named place holders. The requirement is somewhat similar to Template/Text/Html package but slightly different. Using default template packages escapes characters and gets into a route of issues than I wanted. More on forum.golangbridge.org
🌐 forum.golangbridge.org
0
1
November 6, 2016
String interpolation with range
I’m adding a new layout “foo” which for every content whose type is “foo”, it has a linked data file. However, on writing the layout I need to access the linked data using a parameter defined in the front matter, but Hugo refuses to range over the relative path I’ve made using string ... More on discourse.gohugo.io
🌐 discourse.gohugo.io
0
0
July 11, 2017
🌐
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 ... strings. In Go, string interpolation provides a convenient way to construct strings dynamically by combining static text with variable values....
🌐
TutorialsPoint
tutorialspoint.com › go › go_string_interpolation.htm
Go - String Interpolation
In GoLang programming language, string interpolation is the process of integrating expressions into a string literal. When it's necessary to include dynamic values in strings for log statements, error messages, and other purposes, string
Find elsewhere
🌐
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.
🌐
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
🌐
Wikipedia
en.wikipedia.org › wiki › String_interpolation
String interpolation - Wikipedia
1 month ago - While there have been some proposals for string interpolation (which have been rejected), As of 2025 Go does not have interpolated strings.
🌐
GitHub
github.com › golang › go › issues › 34174
proposal: Go 2: string interpolation · Issue #34174 · golang/go
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
go.dev › ref › spec
The Go Programming Language Specification - The Go Programming Language
The three-digit octal (\nnn) and two-digit hexadecimal (\xnn) escapes represent individual bytes of the resulting string; all other escapes represent the (possibly multi-byte) UTF-8 encoding of individual characters.
🌐
Go Forum
forum.golangbridge.org › getting help
Named String Formatting - Getting Help - Go Forum
November 6, 2016 - Hi Folks, I wanted to interpolate string and get the formatted output using named place holders. The requirement is somewhat similar to Template/Text/Html package but slightly different. Using default template pack…
🌐
Calhoun
calhoun.io › 6-tips-for-using-strings-in-go
6 Tips for Using Strings in Go - Calhoun.io
Run it on the Go Playground → https://play.golang.org/p/-nMvx3hKhwR · In many languages you can easily convert any data type into a string simply by concatenating it with a string, or by using string interpolation (eg "ID=#{id}" in ruby). Unfortunately, if you try to do what seems obvious in Go, like casting an int to a string, you are unlikely to get what you expected.
🌐
HUGO
discourse.gohugo.io › support
String interpolation with range - support - HUGO
July 11, 2017 - I’m adding a new layout “foo” which for every content whose type is “foo”, it has a linked data file. However, on writing the layout I need to access the linked data using a parameter defined in the front matter, but Hugo refuses to range over the relative path I’ve made using string interpolation: {{ if .Params.name }} {{ $path := Sprintf "$.Site.Data.%s.items" .Params.name }} {{ range...
🌐
TutorialsPoint
tutorialspoint.com › go › quiz_on_go_string_interpolation.htm
Quiz on Go String Interpolation
Go language is a programming language initially developed at Google in the year 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically-typed language having syntax similar to that of C.
🌐
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.
🌐
W3Schools
w3schools.com › js › js_string_templates.asp
W3Schools.com
JS Graphics JS Canvas JS Plotly JS Chart.js JS Google Chart JS D3.js JS Examples · JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... Template Strings allow variables in strings. Template strings provide an easy way to interpolate variables in strings.
🌐
Vanillacamp
vanillacamp.hashnode.dev › way-to-go-strinterop
Presumably most naïve way for string interpolation in Golang I currently do know
February 25, 2025 - I am learning Go again – this time with special attention to its standard library : TL;DR : Join([]string{"I", ("<" + Itoa(3)), "Golang"}, " ")