Go Printing to Stdout and Stderr: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(23 intermediate revisions by the same user not shown)
Line 2: Line 2:
* [[Go_Language#Printing|Go Language]]
* [[Go_Language#Printing|Go Language]]
* [[Go Code Examples#Code_Examples|Go Code Examples]]
* [[Go Code Examples#Code_Examples|Go Code Examples]]
* [[Go Package fmt|The <tt>fmt</tt> Package]]
=Bootstrapping Functions=
=Bootstrapping Functions=
Both <code>[[#print.28.29|print()]]</code> and <code>[[#println.28.29|println()]]</code> are [[Go_Language#Pre-Declared_Functions|pre-declared functions]], ready to use without any import.
Both <code>[[#print.28.29|print()]]</code> and <code>[[#println.28.29|println()]]</code> are [[Go_Language#Pre-Declared_Functions|pre-declared functions]], ready to use without any import.
<font color=darkkhaki>TODO: https://golang.org/ref/spec#Bootstrapping</font>
==<tt>print()</tt>==
==<tt>print()</tt>==
==<tt>println()</tt>==
==<tt>println()</tt>==
Line 12: Line 16:
</syntaxhighlight>
</syntaxhighlight>


=<tt>fmt.Printf()</tt>=
=<tt>fmt</tt> Functions=
{{Internal|Go_Package_fmt|The <tt>fmt</tt> Package}}
==<tt>fmt.Printf()</tt>==
{{External|https://golang.org/pkg/fmt/#Printf}}
<syntaxhighlight lang='go'>
<syntaxhighlight lang='go'>
import "fmt"
import "fmt"


// ...
// ...
fmt.Printf("something")
fmt.Printf("something %s", "blue")
</syntaxhighlight>
 
==Format Strings==
The format strings contain conversation characters (ex. <code>%s</code>):
<syntaxhighlight lang='go'>
fmt.Printf("Hello %s", "Bob")
</syntaxhighlight>
</syntaxhighlight>
<code>Print()</code> expects a '''format specifier''' (or a '''format string''') as the first argument, which contains [[Go_Package_fmt#Conversion_Characters|conversion characters]] (ex. <code>%s</code>). {{Internal|Go_Package_fmt#Conversion_Characters|Format String &#124; Conversion Characters}}

Latest revision as of 22:00, 22 December 2023

Internal

Bootstrapping Functions

Both print() and println() are pre-declared functions, ready to use without any import.

TODO: https://golang.org/ref/spec#Bootstrapping

print()

println()

func main() {
  println("something")
}

fmt Functions

The fmt Package

fmt.Printf()

https://golang.org/pkg/fmt/#Printf
import "fmt"

// ...
fmt.Printf("something %s", "blue")

Print() expects a format specifier (or a format string) as the first argument, which contains conversion characters (ex. %s).

Format String | Conversion Characters