Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go has a built in "print" function?

Tags:

go

I cam across some code today that suprised me with a 'print' that wasn't defined. After a little playing I determined that you can just use a print to get things dumped to the console

e.g.

 print("Hello World")

So it seems to be some sort of builtin but I can't find any reference to it (and I thought the go rules were lowercase functions never imported anyway)

Is this well known and if so are there other convenience functions or am I just very, very confused?

One other point -- this print doesn't use the magic formatting tricks (%v) of fmt.Printf -- If you print maps or structs you seem to get their address.

like image 670
loghound Avatar asked Jul 16 '13 20:07

loghound


People also ask

What does the print () function do in Python?

Print Function The Python print() function takes in any number of parameters, and prints them out on one line of text. The items are each converted to text form, separated by spaces, and there is a single '\n' at the end (the "newline" char).

How do you print a variable in go?

To print a variable's type, you can use the %T verb in the fmt. Printf() function format. It's the simplest and most recommended way of printing type of a variable. Alternatively, you can use the TypeOf() function from the reflection package reflect .


1 Answers

print and println are defined here.

Their purpose is explained here.

like image 171
zzzz Avatar answered Dec 15 '22 17:12

zzzz