I missed something. Why does …
fmt.Printf("%T\n", a)
fmt.Printf("%T\n", b)
fmt.Printf("%T\n", c)

%T is the type of your variable

a := 1 makes a by default an int, and b := 1.1 make b by default a float64

I kinda get it but not really.
So, when you say “by default” does this mean something that has been preset or predefined by Go?

It is a convention, as far as I know, that 1 is an int and 1.1 is a float64 - see this in the go tutorial about literal data types:

what I am not sure is if h:= 1.1 is a float64 on a 64 bit machine and a float 32 on a 32 bit machine. Could anyone help on this one ?

From the Go tour:

But when the right hand side contains an untyped numeric constant, the new variable may be an int, float64, or complex128 depending on the precision of the constant:

i := 42           // int
f := 3.142        // float64
g := 0.867 + 0.5i // complex128

You can confirm this on the playground (which has a 32 bit arch) by seeing that 1.1 is a float64, 1 an int, and int's size is 4 bytes (32 bits):

The first paragraph is quite helpful.

The second paragraph is interesting

What does the “//” mean?
Bear with me. I’m like a baby learning to talk. :rofl:

It starts a comment.

Interesting. What does “\n” mean?

So in" i := 42 // int", the “//int” is a commentary on the foregoing? but not a part of the program?

Correct. Anything on the line starting with // is ignored by the compiler, to the end of that same line.

I know you are just getting started, but I suggest that as soon as you can (and this applies to everyone), get used to looking in the official specification for definitive answers. Compared to other languages, Go’s language specification is surprisingly easy to read! Comments are about the simplest part of any programming language, so it’s a good place to start.

1 Like

It’s a symbol for a “newline”. In “baby talk”, it means that your fmt.Printf() statements result in


rather than


Remove the /n’s and try it. :wink:

Suggested reading:

Or if you don’t mind spending a little money, look for his book “Introducing Go” by O’Reilly. It’s a good book for people who are just starting with Go and programming.


Very helpful!

yes this is very helpful
learn go tutorial

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.