String formatting in Go without printing: how to save the result to a variable?
Hello everyone! I just started learning Go and encountered a problem. In other languages, like Python, I'm used to using something like `f"Hello, {name}"` or `.format()` to create a formatted string and save it to a variable without immediately printing it to the screen.
In Go, I see the `fmt.Printf()` function, which formats and prints text perfectly, but it immediately outputs the result to the console. But what if I just need to get a string to use it later? For example, I'm writing a function that generates HTML code or creates a log message, but I don't want it to be printed immediately — I want to save it to a variable and return it from the function.
Here's an example of my code:
```go
package main
import "fmt"
func main() {
name := "Anna"
age := 30
// This is what I know how to do, but
```
No answers yet.
Log in to leave an answer