Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think one of the string format examples missing the type formatter:

fmt.Println("it's a", i)

Should be something like:

fmt.Println("it's a %T", i)

See http://golang.org/pkg/fmt/ for more options.

[update]

Forgot they allowed to send pull requests; done :)



Println does not take format strings. You're thinking of Printf.


Yup, forgot to edit that :-/


That should be Printf. With Println you get "it's a %T 43". With Printf you get "it's a int"


Are you mixing up Println and Printf?


No, it's correct. It's meant to print "it's a 84".


Would't you expect either "it's 84" or "it's a(n) int|decimal|other_type"?

I figured they ment to do the latter, since the next print function outputs: "it's a string".


Since c is a chan int it can only be an int, no other type. You could directly write fmt.Println("it's an int").


I just tried it, both seem correct as fmt.PrintLn takes multiple inputs




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: