Reputation: 1271
I can't expand variables with fmt.Println().
package main
import "fmt"
func main(){
old := 20
fmt.Println("I'm %g years old.",old)
}
result =>
I'm %g years old.
20
Upvotes: 1
Views: 4966
Reputation: 166626
Use Printf
not Println
. Use %d
for old
which is type int
. Add a newline.
For example,
package main
import "fmt"
func main() {
old := 20
fmt.Printf("I'm %d years old.\n", old)
}
Output:
I'm 20 years old.
Upvotes: 7
Reputation: 57659
As the documentation for fmt.Println
states, this function does not support format specifiers. Use fmt.Printf
instead.
Upvotes: 1