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
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
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.
", old)
}
Output:
I'm 20 years old.